prompt_pwd: full-dirs set to 0 means not even last component is safe

Alternative is to print an error.
This commit is contained in:
Fabian Homborg 2021-04-11 21:46:56 +02:00
parent af2952dd2f
commit 6c1ec98e92
2 changed files with 5 additions and 1 deletions

View File

@ -39,6 +39,10 @@ function prompt_pwd --description 'Print the current working directory, shortene
set -l all (string split -m (math $fish_prompt_pwd_full_dirs - 1) -r / $tmp) set -l all (string split -m (math $fish_prompt_pwd_full_dirs - 1) -r / $tmp)
set tmp $all[1] set tmp $all[1]
set full $all[2..] 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 end
string join / (string replace -ar '(\.?[^/]{'"$fish_prompt_pwd_dir_length"'})[^/]*/' '$1/' $tmp) $full string join / (string replace -ar '(\.?[^/]{'"$fish_prompt_pwd_dir_length"'})[^/]*/' '$1/' $tmp) $full

View File

@ -10,4 +10,4 @@ prompt_pwd -D 2 /usr/share/fish/tools/web_config/sample_prompts
# CHECK: /u/s/f/t/web_config/sample_prompts # CHECK: /u/s/f/t/web_config/sample_prompts
prompt_pwd -D 0 /usr/share/fish/tools/web_config/sample_prompts prompt_pwd -D 0 /usr/share/fish/tools/web_config/sample_prompts
# CHECK: /u/s/f/t/w/sample_prompts # CHECK: /u/s/f/t/w/s