mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-27 19:53:36 +08:00
11a60c8374
I hate doing this but I am tired of touching a fish script as part of some change and having `make style` radically change it. Which makes editing fish scripts more painful than it needs to be. It is time to do a wholesale reformatting of these scripts to conform to the documented style as implemented by the `fish_indent` program.
24 lines
806 B
Fish
24 lines
806 B
Fish
function prompt_pwd --description "Print the current working directory, shortened to fit the prompt"
|
|
set -q argv[1]
|
|
and switch $argv[1]
|
|
case -h --help
|
|
__fish_print_help prompt_pwd
|
|
return 0
|
|
end
|
|
|
|
# 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 ~
|
|
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
|