mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-28 13:53:10 +00:00
Allow passing directories to prompt_pwd
This allows us to test it without cd-ing about the place.
This commit is contained in:
parent
7a8feb4656
commit
af2952dd2f
2 changed files with 35 additions and 17 deletions
|
@ -1,6 +1,6 @@
|
|||
function prompt_pwd --description 'Print the current working directory, shortened to fit the prompt'
|
||||
set -l options h/help d/dir-length= D/full-length-dirs=
|
||||
argparse -n prompt_pwd --max-args=0 $options -- $argv
|
||||
argparse -n prompt_pwd $options -- $argv
|
||||
or return
|
||||
|
||||
if set -q _flag_help
|
||||
|
@ -8,6 +8,9 @@ function prompt_pwd --description 'Print the current working directory, shortene
|
|||
return 0
|
||||
end
|
||||
|
||||
set -q argv[1]
|
||||
or set argv $PWD
|
||||
|
||||
set -ql _flag_d
|
||||
and set -l fish_prompt_pwd_dir_length $_flag_d
|
||||
|
||||
|
@ -19,11 +22,12 @@ function prompt_pwd --description 'Print the current working directory, shortene
|
|||
and set fish_prompt_pwd_full_dirs $_flag_D
|
||||
|
||||
set -q fish_prompt_pwd_full_dirs
|
||||
or set -l fish_prompt_pwd_full_dirs 0
|
||||
or set -l fish_prompt_pwd_full_dirs 1
|
||||
|
||||
for path in $argv
|
||||
# Replace $HOME with "~"
|
||||
set -l realhome ~
|
||||
set -l tmp (string replace -r '^'"$realhome"'($|/)' '~$1' $PWD)
|
||||
set -l tmp (string replace -r '^'"$realhome"'($|/)' '~$1' $path)
|
||||
|
||||
if test "$fish_prompt_pwd_dir_length" -eq 0
|
||||
echo $tmp
|
||||
|
@ -39,4 +43,5 @@ function prompt_pwd --description 'Print the current working directory, shortene
|
|||
|
||||
string join / (string replace -ar '(\.?[^/]{'"$fish_prompt_pwd_dir_length"'})[^/]*/' '$1/' $tmp) $full
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
13
tests/checks/prompt.fish
Normal file
13
tests/checks/prompt.fish
Normal file
|
@ -0,0 +1,13 @@
|
|||
#RUN: %fish %s
|
||||
|
||||
prompt_pwd -d 1 /foo/bar/baz
|
||||
# CHECK: /f/b/baz
|
||||
|
||||
prompt_pwd /usr/share/fish/tools/web_config/sample_prompts
|
||||
# CHECK: /u/s/f/t/w/sample_prompts
|
||||
|
||||
prompt_pwd -D 2 /usr/share/fish/tools/web_config/sample_prompts
|
||||
# CHECK: /u/s/f/t/web_config/sample_prompts
|
||||
|
||||
prompt_pwd -D 0 /usr/share/fish/tools/web_config/sample_prompts
|
||||
# CHECK: /u/s/f/t/w/sample_prompts
|
Loading…
Reference in a new issue