diff --git a/init/fish_function.fish b/init/fish_function.fish index ab7133ec2..89e9859df 100644 --- a/init/fish_function.fish +++ b/init/fish_function.fish @@ -180,17 +180,17 @@ function open -d "Open file in default application" end # -# Print the current working directory. If it is too long, it will be -# ellipsised. This function is used by the default prompt command. +# Print the current working directory in a shortened form.This +# function is used by the default prompt command. # function prompt_pwd -d "Print the current working directory, shortend to fit the prompt" - set -l wd (pwd) - set -l res (echo $wd|sed -e 's-/\([^/]\)\([^/]*\)-/\1-g') - if test $wd != '~' - set res $res(echo $wd|sed -e 's-.*/[^/]\([^/]*$\)-\1-') + if test "$PWD" != "$HOME" + printf "%s" (echo $PWD|sed -e "s|^$HOME|~|" -e 's-/\([^/]\)\([^/]*\)-/\1-g') + echo $PWD|sed -e 's-.*/[^/]\([^/]*$\)-\1-' + else + echo '~' end - echo $res end # diff --git a/init/fish_interactive.fish.in b/init/fish_interactive.fish.in index 435fa5a1e..8a38509c9 100644 --- a/init/fish_interactive.fish.in +++ b/init/fish_interactive.fish.in @@ -26,7 +26,19 @@ end # long it is. function fish_prompt -d (_ "Write out the prompt") - printf '%s@%s %s%s%s> \n' (whoami) (hostname|cut -d . -f 1) (set_color $fish_color_cwd) (prompt_pwd) (set_color normal) + if not set -q __fish_prompt_whoami + set -g __fish_prompt_whoami (whoami) + end + + if not set -q __fish_prompt_hostname + set -g __fish_prompt_hostname (hostname|cut -d . -f 1) + end + + if not set -q __fish_prompt_normal + set -g __fish_prompt_normal (set_color normal) + end + + printf '%s@%s %s%s%s> \n' $__fish_prompt_whoami $__fish_prompt_hostname (set_color $fish_color_cwd) (prompt_pwd) $__fish_prompt_normal end #