Fix index out of bounds

When current dir is the first one in history. There is no previous dirs.
This commit is contained in:
EMayej Bee 2016-09-12 12:30:39 +08:00 committed by Kurtis Rader
parent f9115b5ef1
commit 85cd372a4e

View File

@ -8,11 +8,13 @@ function dirh --description "Print the current directory history (the prev and n
end end
set -l dirc (count $dirprev) set -l dirc (count $dirprev)
set -l dirprev_rev $dirprev[-1..1] if test $dirc -gt 0
# This can't be (seq $dirc -1 1) because of BSD. set -l dirprev_rev $dirprev[-1..1]
set -l dirnum (seq 1 $dirc) # This can't be (seq $dirc -1 1) because of BSD.
for i in $dirnum[-1..1] set -l dirnum (seq 1 $dirc)
printf '%2d) %s\n' $i $dirprev_rev[$i] for i in $dirnum[-1..1]
printf '%2d) %s\n' $i $dirprev_rev[$i]
end
end end
echo (set_color $fish_color_history_current)' ' $PWD(set_color normal) echo (set_color $fish_color_history_current)' ' $PWD(set_color normal)