mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-12 07:57:22 +00:00
Optimize the fish_prompt function
darcs-hash:20060128102551-ac50b-58580c29fd9537e502bacaad7949433010b5a04b.gz
This commit is contained in:
parent
7f195b2f23
commit
00dea8a082
2 changed files with 20 additions and 8 deletions
|
@ -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
|
||||
|
||||
#
|
||||
|
|
|
@ -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
|
||||
|
||||
#
|
||||
|
|
Loading…
Reference in a new issue