more changes to better handle undef vars

This is only needed if we make undefined vars an error as proposed in
issue #4163 but it's a good idea anyway.
This commit is contained in:
Kurtis Rader 2017-07-03 10:16:31 -07:00
parent 4f345fdee7
commit 763063e741
4 changed files with 13 additions and 6 deletions

View file

@ -31,6 +31,8 @@ function cd --description "Change directory"
set -l cd_status $status
if test $cd_status -eq 0 -a "$PWD" != "$previous"
set -q dirprev
or set -l dirprev
set -q dirprev[$MAX_DIR_HIST]
and set -e dirprev[1]
set -g dirprev $dirprev $previous

View file

@ -8,12 +8,11 @@ function popd --description "Pop directory from the stack and cd to it"
end
end
if test $dirstack[1]
if set -q dirstack[1]
cd $dirstack[1]
set -e dirstack[1]
else
printf (_ "%s: Directory stack is empty…\n") popd 1>&2
return 1
end
set -e dirstack[1]
end

View file

@ -18,10 +18,13 @@ function pushd --description 'Push directory to stack'
end
end
set -q dirstack
or set -g dirstack
# emulate bash: an empty pushd should switch the top of dirs
if test (count $argv) -eq 0
if not set -q argv[1]
# check that the stack isn't empty
if test (count $dirstack) -eq 0
if not set -q dirstack[1]
echo "pushd: no other directory"
return 1
end

View file

@ -24,7 +24,10 @@ end
set TERM xterm
set -e ITERM_PROFILE
source test_util.fish (status -f) $argv; or exit
set -q argv
or set argv
source test_util.fish (status -f) $argv
or exit
say -o cyan "Testing high level script functionality"