Fish Interactive Shell 完整路径

发布于 2024-07-20 11:12:06 字数 205 浏览 12 评论 0原文

Fish Interactive shell 中有没有办法显示完整路径。 目前,当我导航到目录时,我会得到以下 shell。

millermj@Dodore ~/o/workspace

但我宁愿看到

millermj@Dodore ~/o-town/workspace

Is there a way in the Fish Interactive shell for the full path to be displayed. Currently when I navigate to a directory I get the following shell.

millermj@Dodore ~/o/workspace

but I would rather see

millermj@Dodore ~/o-town/workspace

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

哑剧 2024-07-27 11:12:07

使用新的fishshell (v2.3),您可以执行set -U Fish_prompt_pwd_dir_length 0。 并且它将使用完整路径。 我还使用 dartfish 作为我的主题。 请参阅下面的示例:

“在此处输入图像描述"

With the new fishshell (v2.3) you can do set -U fish_prompt_pwd_dir_length 0. And it will use the full path. I also use dartfish for my theme. See example below:

enter image description here

江挽川 2024-07-27 11:12:07

这是我的 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提示_pwd。 根据您的喜好显示提示后,请使用 funcsaveprompt_pwd 使该行为在以后的会话中持续存在。

Here's my version of prompt_pwd that should display what you're looking for:

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

This will display the tilde for the home directory, as usual, but removes the sed command that only pulls the first letter from each directory when you're a few directories deep.

To edit prompt_pwd use funced. It will allow you to interactively alter the function. From the command line type funced prompt_pwd. Once the prompt is displaying to your liking, use funcsave prompt_pwd to make the behavior persist in future sessions.

热情消退 2024-07-27 11:12:07

我个人不喜欢触及共享/默认值。 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

I personally don't like touching the shared/defaults. Fish has a great functions design, so leverage that.

Create ~/.config/fish/functions/prompt_long_pwd.fish with the contents:

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

Then simply edit your ~/.config/fish/functions/fish_prompt.fish to use prompt_long_pwd. Here is the custom prompt that I use:

~/.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
躲猫猫 2024-07-27 11:12:07

创建 ~/.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 正常)(prompt_long_pwd) (set_color 正常)

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

此答案是根据之前的答案修改的,并显示完整目录,同时保留默认提示的其他部分。 关键的变化在于 ~/.config/fish/functions/prompt_long_pwd.fish 中的表达式。

Create ~/.config/fish/functions/prompt_long_pwd.fish with:

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

In ~/.config/fish/functions/fish_prompt.fish change (prompt_pwd) (set_color normal) to (prompt_long_pwd) (set_color normal).

(prompt_pwd) replaces the directory name with the first letter of the directory, which I too sometimes find annoying. You can also probably modify the original command prompt_pwd, I have not tried it.

This answer is modified from the earlier answer and shows the full directory while keeping the other parts of the default prompt. The key change is in the expression in ~/.config/fish/functions/prompt_long_pwd.fish.

梦初启 2024-07-27 11:12:07

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

Just thought I'd give everyone a heads up if you stumbled on this and your fish is not responding to the fish_prompt_pwd_dir_length variable try upgrading omf, and then update your omf themes that you're using. Then do some combination of selecting a different theme, reopening the shell, and selecting a different theme again. This is what worked for me. Good luck!

战皆罪 2024-07-27 11:12:07

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

The prompt_pwd function determines the function to be displayed. You should be able to write your own version to get what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文