简体   繁体   中英

Fish Interactive Shell full path

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

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:

在此处输入图片说明

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.

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

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 .

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM