don't shorten pwd
This commit is contained in:
@@ -29,3 +29,4 @@ SETUVAR fish_pager_color_description:yellow\x1e\x2di
|
|||||||
SETUVAR fish_pager_color_prefix:normal\x1e\x2d\x2dbold\x1e\x2d\x2dunderline
|
SETUVAR fish_pager_color_prefix:normal\x1e\x2d\x2dbold\x1e\x2d\x2dunderline
|
||||||
SETUVAR fish_pager_color_progress:brwhite\x1e\x2d\x2dbackground\x3dcyan
|
SETUVAR fish_pager_color_progress:brwhite\x1e\x2d\x2dbackground\x3dcyan
|
||||||
SETUVAR fish_pager_color_selected_background:\x2dr
|
SETUVAR fish_pager_color_selected_background:\x2dr
|
||||||
|
SETUVAR fish_prompt_pwd_dir_length:100
|
||||||
|
|||||||
@@ -27,5 +27,57 @@ function fish_prompt --description 'Write out the prompt'
|
|||||||
set -l statusb_color (set_color $bold_flag $fish_color_status)
|
set -l statusb_color (set_color $bold_flag $fish_color_status)
|
||||||
set -l prompt_status (__fish_print_pipestatus "[" "]" "|" "$status_color" "$statusb_color" $last_pipestatus)
|
set -l prompt_status (__fish_print_pipestatus "[" "]" "|" "$status_color" "$statusb_color" $last_pipestatus)
|
||||||
|
|
||||||
echo -n -s (prompt_login)' ' (set_color $color_cwd) (pwd) $normal (fish_vcs_prompt) $normal " "$prompt_status $suffix " "
|
echo -n -s (prompt_login)' ' (set_color $color_cwd) (prompt_pwd) $normal (fish_vcs_prompt) $normal " "$prompt_status $suffix " "
|
||||||
|
end
|
||||||
|
|
||||||
|
function prompt_pwd --description 'short CWD for the prompt'
|
||||||
|
set -l options h/help d/dir-length= D/full-length-dirs=
|
||||||
|
argparse -n prompt_pwd $options -- $argv
|
||||||
|
or return
|
||||||
|
|
||||||
|
if set -q _flag_help
|
||||||
|
__fish_print_help prompt_pwd
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
set -q argv[1]
|
||||||
|
or set argv $PWD
|
||||||
|
|
||||||
|
set -ql _flag_d
|
||||||
|
and set -l fish_prompt_pwd_dir_length $_flag_d
|
||||||
|
|
||||||
|
set -q fish_prompt_pwd_dir_length
|
||||||
|
or set -l fish_prompt_pwd_dir_length 1
|
||||||
|
|
||||||
|
set -l fulldirs 0
|
||||||
|
set -ql _flag_D
|
||||||
|
and set -l fish_prompt_pwd_full_dirs $_flag_D
|
||||||
|
|
||||||
|
set -q fish_prompt_pwd_full_dirs
|
||||||
|
or set -l fish_prompt_pwd_full_dirs 1
|
||||||
|
|
||||||
|
for path in $argv
|
||||||
|
# Replace $HOME with "~"
|
||||||
|
set -l realhome (string escape --style=regex -- ~)
|
||||||
|
set -l tmp (string replace -r '^'"$realhome"'($|/)' '~$1' $path)
|
||||||
|
|
||||||
|
if test "$fish_prompt_pwd_dir_length" -eq 0
|
||||||
|
echo $tmp
|
||||||
|
else
|
||||||
|
# Shorten to at most $fish_prompt_pwd_dir_length characters per directory
|
||||||
|
# with full-length-dirs components left at full length.
|
||||||
|
set -l full
|
||||||
|
if test $fish_prompt_pwd_full_dirs -gt 0
|
||||||
|
set -l all (string split -m (math $fish_prompt_pwd_full_dirs - 1) -r / $tmp)
|
||||||
|
set tmp $all[1]
|
||||||
|
set full $all[2..]
|
||||||
|
else if test $fish_prompt_pwd_full_dirs -eq 0
|
||||||
|
# 0 means not even the last component is kept
|
||||||
|
string replace -ar '(\.?[^/]{'"$fish_prompt_pwd_dir_length"'})[^/]*' '$1' $tmp
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
|
||||||
|
string join / -- (string replace -ar -- '(\.?[^/]{'"$fish_prompt_pwd_dir_length"'})[^/]*/' '$1/' $tmp) $full
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user