Fish Interactive Shell full path
Question
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
Solution
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:
OTHER TIPS
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
The prompt_pwd
function determines the function to be displayed. You should be able to write your own version to get what you want.