convert popd and pushd to use argparse

This commit is contained in:
Kurtis Rader 2017-07-13 11:31:08 -07:00
parent 5ac8c42fad
commit 05aae4764b
2 changed files with 17 additions and 16 deletions

View file

@ -1,12 +1,12 @@
function popd --description "Pop directory from the stack and cd to it" function popd --description "Pop directory from the stack and cd to it"
if count $argv >/dev/null set -l options 'h/help'
switch $argv[1] argparse -n popd --max-args=0 $options -- $argv
case -h --h --he --hel --help or return
if set -q _flag_help
__fish_print_help popd __fish_print_help popd
return 0 return 0
end end
end
if set -q dirstack[1] if set -q dirstack[1]
cd $dirstack[1] cd $dirstack[1]

View file

@ -1,15 +1,16 @@
function pushd --description 'Push directory to stack' function pushd --description 'Push directory to stack'
set -l rot_r set -l options 'h/help'
set -l rot_l argparse -n pushd --max-args=1 $options -- $argv
or return
if count $argv >/dev/null if set -q _flag_help
# check for --help
switch $argv[1]
case -h --h --he --hel --help
__fish_print_help pushd __fish_print_help pushd
return 0 return 0
end end
set -l rot_r
set -l rot_l
if set -q argv[1]
# emulate bash by checking if argument of form +n or -n # emulate bash by checking if argument of form +n or -n
if string match -qr '^-[0-9]+$' -- $argv[1] if string match -qr '^-[0-9]+$' -- $argv[1]
set rot_r (string sub -s 2 -- $argv[1]) set rot_r (string sub -s 2 -- $argv[1])