【问题标题】:Fish Interactive Shell full pathFish Interactive Shell 完整路径
【发布时间】:2010-10-26 09:40:52
【问题描述】:

Fish Interactive shell 中是否有办法显示完整路径。目前,当我导航到一个目录时,我得到了以下 shell。

millermj@Dodore ~/o/workspace

但我更愿意看到

millermj@Dodore ~/o-town/workspace

【问题讨论】:

    标签: macos unix path fish


    【解决方案1】:

    只是想如果您偶然发现此问题并且您的鱼没有响应 fish_prompt_pwd_dir_length 变量,我会提醒大家尝试升级 omf,然后更新您正在使用的 omf 主题。然后做一些选择不同主题的组合,重新打开外壳,然后再次选择不同的主题。这对我有用。祝你好运!

    【讨论】:

      【解决方案2】:

      使用:创建~/.config/fish/functions/prompt_long_pwd.fish

      function prompt_long_pwd --description 'Print the full working directory'
              echo $PWD
      end
      

      ~/.config/fish/functions/fish_prompt.fish 中将(prompt_pwd) (set_color normal) 更改为(prompt_long_pwd) (set_color normal)

      (prompt_pwd) 将目录名称替换为目录的第一个字母,我有时也觉得这很烦人。你也可以大概修改一下原来的命令prompt_pwd,我没试过。

      这个答案是从之前的answer 修改而来的,它显示了完整的目录,同时保留了默认提示的其他部分。关键变化在于~/.config/fish/functions/prompt_long_pwd.fish 中的表达式。

      【讨论】:

        【解决方案3】:

        使用新的fishshell (v2.3),您可以使用set -U fish_prompt_pwd_dir_length 0。它将使用完整路径。我也使用dartfish 作为我的主题。请参见下面的示例:

        【讨论】:

        • 我应该添加我使用 dartfish 主题。也许这是主题的一部分?
        • 不是主题的一部分。这适用于我的鱼2.3.1
        • 上述命令(set -U fish_prompt_pwd_dir_length 0)可以在 config.fish 中配置。如果这里有人需要更多信息。
        【解决方案4】:

        我个人不喜欢触摸共享/默认值。 Fish 具有出色的功能设计,因此请充分利用它。

        使用内容创建~/.config/fish/functions/prompt_long_pwd.fish

        function prompt_long_pwd --description 'Print the current working directory'
                echo $PWD | sed -e "s|^$HOME|~|" -e 's|^/private||'
        end
        

        然后只需编辑您的~/.config/fish/functions/fish_prompt.fish 以使用prompt_long_pwd。这是我使用的自定义提示:

        ~/.config/fish/config.fish

        set -g __fish_git_prompt_show_informative_status 1
        set -g __fish_git_prompt_hide_untrackedfiles 1
        
        set -g __fish_git_prompt_color_branch magenta bold
        set -g __fish_git_prompt_showupstream "informative"
        set -g __fish_git_prompt_char_upstream_ahead "↑"
        set -g __fish_git_prompt_char_upstream_behind "↓"
        set -g __fish_git_prompt_char_upstream_prefix ""
        
        set -g __fish_git_prompt_char_stagedstate "●"
        set -g __fish_git_prompt_char_dirtystate "✚"
        set -g __fish_git_prompt_char_untrackedfiles "…"
        set -g __fish_git_prompt_char_conflictedstate "✖"
        set -g __fish_git_prompt_char_cleanstate "✔"
        
        set -g __fish_git_prompt_color_dirtystate blue
        set -g __fish_git_prompt_color_stagedstate yellow
        set -g __fish_git_prompt_color_invalidstate red
        set -g __fish_git_prompt_color_untrackedfiles $fish_color_normal
        set -g __fish_git_prompt_color_cleanstate green bold
        

        ~/.config/fish/functions/fish_prompt.fish

        function fish_prompt --description 'Write out the prompt'
        
            set -l last_status $status
        
            if not set -q __fish_prompt_normal
                set -g __fish_prompt_normal (set_color normal)
            end
        
            # PWD
            set_color $fish_color_cwd
            echo -n (prompt_long_pwd)
            set_color normal
        
            printf '%s ' (__fish_git_prompt)
        
            if not test $last_status -eq 0
            set_color $fish_color_error
            end
        
            echo -n '$ '
        
        end
        

        【讨论】:

        • 您的大部分回答与回答问题无关。人们希望你删除不相关的部分。
        【解决方案5】:

        这是我的 prompt_pwd 版本,应该会显示您要查找的内容:

        function prompt_pwd --description 'Print the current working directory, NOT shortened to fit the prompt'
            if test "$PWD" != "$HOME"
                printf "%s" (echo $PWD|sed -e 's|/private||' -e "s|^$HOME|~|")
            else
                echo '~'
            end
        
        end
        

        这将像往常一样显示主目录的波浪号,但删除了sed 命令,该命令仅在您深入几个目录时从每个目录中提取第一个字母。

        要编辑prompt_pwd,请使用funced。它将允许您以交互方式更改功能。从命令行输入funced prompt_pwd。根据您的喜好显示提示后,使用funcsave prompt_pwd 使该行为在以后的会话中持续存在。

        【讨论】:

        • 你实际上并不需要if,在主目录中,sed 仍然会产生~
        • 您的版本在我的机器上显示为/V/Y/U/s/D/p001 而不是Volumes/Yosemite I am/Users/slippyd/Desktop/p001echo $PWD) 的结果。
        • 在fish shell中输入fish_config,它会在你的浏览器中打开一个fish-config web界面。现在您可以从一长串提示选项中进行选择..
        【解决方案6】:

        prompt_pwd 函数确定要显示的函数。你应该能够编写自己的版本来获得你想要的。

        【讨论】:

          猜你喜欢
          • 2015-09-23
          • 1970-01-01
          • 1970-01-01
          • 2015-10-26
          • 1970-01-01
          • 2017-03-16
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多