2015-10-06 01:20:09 +08:00
|
|
|
function prompt_pwd --description "Print the current working directory, shortened to fit the prompt"
|
2017-07-14 04:57:17 +08:00
|
|
|
set -l options 'h/help'
|
|
|
|
argparse -n prompt_pwd --max-args=0 $options -- $argv
|
|
|
|
or return
|
|
|
|
|
|
|
|
if set -q _flag_help
|
|
|
|
__fish_print_help prompt_pwd
|
|
|
|
return 0
|
2016-11-28 13:27:22 +08:00
|
|
|
end
|
2015-12-17 22:17:28 +08:00
|
|
|
|
2016-11-28 13:27:22 +08: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
|
2015-10-10 06:37:43 +08:00
|
|
|
|
2016-11-28 13:27:22 +08:00
|
|
|
# Replace $HOME with "~"
|
|
|
|
set realhome ~
|
|
|
|
set -l tmp (string replace -r '^'"$realhome"'($|/)' '~$1' $PWD)
|
2015-10-10 06:37:43 +08:00
|
|
|
|
2016-11-28 13:27:22 +08:00
|
|
|
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
|
2006-02-12 21:14:21 +08:00
|
|
|
end
|