aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/functions/prompt_pwd.fish
diff options
context:
space:
mode:
Diffstat (limited to 'share/functions/prompt_pwd.fish')
-rw-r--r--share/functions/prompt_pwd.fish13
1 files changed, 12 insertions, 1 deletions
diff --git a/share/functions/prompt_pwd.fish b/share/functions/prompt_pwd.fish
index 4c766599..c519c6cc 100644
--- a/share/functions/prompt_pwd.fish
+++ b/share/functions/prompt_pwd.fish
@@ -1,4 +1,15 @@
function prompt_pwd --description "Print the current working directory, shortened to fit the prompt"
+ # 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 realhome ~
- string replace -r '^'"$realhome"'($|/)' '~$1' $PWD | string replace -ar '([^/.])[^/]*/' '$1/'
+ 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