mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-25 20:33:08 +00:00
convert nextd
to use argparse
This commit is contained in:
parent
5cf2a50269
commit
abef2cc422
1 changed files with 28 additions and 43 deletions
|
@ -1,45 +1,33 @@
|
|||
|
||||
function nextd --description "Move forward in the directory history"
|
||||
set -l options 'h/help' 'l/list'
|
||||
argparse $options -- $argv
|
||||
or return
|
||||
|
||||
if count $argv >/dev/null
|
||||
switch $argv[1]
|
||||
case -h --h --he --hel --help
|
||||
if set -q _flag_help
|
||||
__fish_print_help nextd
|
||||
return 0
|
||||
end
|
||||
|
||||
if set -q argv[2]
|
||||
printf (_ "%s: Too many arguments") nextd >&2
|
||||
return 1
|
||||
end
|
||||
|
||||
# Parse arguments
|
||||
set -l show_hist 0
|
||||
set -l times 1
|
||||
if count $argv >/dev/null
|
||||
for i in (seq (count $argv))
|
||||
switch $argv[$i]
|
||||
case '-l' --l --li --lis --list
|
||||
set show_hist 1
|
||||
continue
|
||||
case '-*'
|
||||
printf (_ "%s: Unknown option %s\n" ) nextd $argv[$i]
|
||||
return 1
|
||||
case '*'
|
||||
if test $argv[$i] -ge 0 ^/dev/null
|
||||
set times $argv[$i]
|
||||
if set -q $argv[1]
|
||||
if test $argv[1] -ge 0 ^/dev/null
|
||||
set times $argv[1]
|
||||
else
|
||||
printf (_ "%s: The number of positions to skip must be a non-negative integer\n" ) nextd
|
||||
printf (_ "%s: The number of positions to skip must be a non-negative integer\n") nextd
|
||||
return 1
|
||||
end
|
||||
continue
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Traverse history
|
||||
set -l code 1
|
||||
if count $times >/dev/null
|
||||
for i in (seq $times)
|
||||
# Try one step backward
|
||||
if __fish_move_last dirnext dirprev
|
||||
|
||||
# We consider it a success if we were able to do at least 1 step
|
||||
# (low expectations are the key to happiness ;)
|
||||
set code 0
|
||||
|
@ -47,18 +35,15 @@ function nextd --description "Move forward in the directory history"
|
|||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Show history if needed
|
||||
if test $show_hist = 1
|
||||
if set -q _flag_list
|
||||
dirh
|
||||
end
|
||||
|
||||
# Set direction for 'cd -'
|
||||
if test $code = 0 ^/dev/null
|
||||
set -g __fish_cd_direction prev
|
||||
end
|
||||
test $code = 0
|
||||
and set -g __fish_cd_direction prev
|
||||
|
||||
# All done
|
||||
return $code
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue