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"
if count $argv >/dev/null
switch $argv[1]
case -h --h --he --hel --help
set -l options 'h/help'
argparse -n popd --max-args=0 $options -- $argv
or return
if set -q _flag_help
__fish_print_help popd
return 0
end
end
if set -q dirstack[1]
cd $dirstack[1]

View file

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