diff options
author | 2006-01-28 20:25:51 +1000 | |
---|---|---|
committer | 2006-01-28 20:25:51 +1000 | |
commit | 00dea8a082445615cf4c19d04bf608c876794596 (patch) | |
tree | 07e3330e3765da8a7100053569095902c212d022 /init | |
parent | 7f195b2f23e3d5b13640f45ea85f4e357441dc00 (diff) |
Optimize the fish_prompt function
darcs-hash:20060128102551-ac50b-58580c29fd9537e502bacaad7949433010b5a04b.gz
Diffstat (limited to 'init')
-rw-r--r-- | init/fish_function.fish | 14 | ||||
-rw-r--r-- | init/fish_interactive.fish.in | 14 |
2 files changed, 20 insertions, 8 deletions
diff --git a/init/fish_function.fish b/init/fish_function.fish index ab7133ec..89e9859d 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 435fa5a1..8a38509c 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 # |