fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
2bab8b583
master
1# localization: tier1 2function prompt_pwd --description'short CWD for the prompt' 3set -l options h/help d/dir-length= D/full-length-dirs= 4argparse -n prompt_pwd$options --$argv 5or return 6 7if set -q _flag_help 8__fish_print_help prompt_pwd 9return 0 10end 11 12set -q argv[ 1 ] 13or set argv$PWD 14 15set -ql _flag_d 16and set -l fish_prompt_pwd_dir_length$_flag_d 17 18set -q fish_prompt_pwd_dir_length 19or set -l fish_prompt_pwd_dir_length1 20 21set -l fulldirs0 22set -ql _flag_D 23and set -l fish_prompt_pwd_full_dirs$_flag_D 24 25set -q fish_prompt_pwd_full_dirs 26or set -l fish_prompt_pwd_full_dirs1 27 28for pathin $argv 29# Strip control characters to avoid injecting terminal escape sequences into the prompt. 30set -l tmp( __fish_unexpand_tilde $path | string replace -ra'[[:cntrl:]]' '' ) 31 32if test " $fish_prompt_pwd_dir_length " -eq 0 33echo $tmp 34else 35# Shorten to at most $fish_prompt_pwd_dir_length characters per directory 36# with full-length-dirs components left at full length. 37set -l full 38if test $fish_prompt_pwd_full_dirs -gt 0 39set -l all( string split -m( math $fish_prompt_pwd_full_dirs -1 ) -r /$tmp ) 40set tmp$all [ 1 ] 41set full$all [ 2 .. ] 42else if test $fish_prompt_pwd_full_dirs -eq 0 43# 0 means not even the last component is kept 44string replace -ar'(\.?[^/]{'" $fish_prompt_pwd_dir_length "'})[^/]*' '$1' $tmp 45continue 46end 47 48string join / --( string replace -ar --'(\.?[^/]{'" $fish_prompt_pwd_dir_length "'})[^/]*/' '$1/' $tmp ) $full 49end 50end 51end