fish-shell/share/functions/prompt_pwd.fish

26 lines
859 B
Fish
Raw Normal View History

function prompt_pwd --description "Print the current working directory, shortened to fit the prompt"
set -l options h/help
2017-07-13 20:57:17 +00:00
argparse -n prompt_pwd --max-args=0 $options -- $argv
or return
if set -q _flag_help
__fish_print_help prompt_pwd
return 0
end
2015-12-17 14:17:28 +00:00
# This allows overriding fish_prompt_pwd_dir_length from the outside (global or universal) without leaking it
set -q fish_prompt_pwd_dir_length
or set -l fish_prompt_pwd_dir_length 1
# Replace $HOME with "~"
set -l realhome ~
set -l tmp (string replace -r '^'"$realhome"'($|/)' '~$1' $PWD)
if [ $fish_prompt_pwd_dir_length -eq 0 ]
echo $tmp
else
# Shorten to at most $fish_prompt_pwd_dir_length characters per directory
string replace -ar '(\.?[^/]{'"$fish_prompt_pwd_dir_length"'})[^/]*/' '$1/' $tmp
end
end