From 85cd372a4ecdc95e68139e87892437f7ecc66809 Mon Sep 17 00:00:00 2001 From: EMayej Bee Date: Mon, 12 Sep 2016 12:30:39 +0800 Subject: [PATCH] Fix index out of bounds When current dir is the first one in history. There is no previous dirs. --- share/functions/dirh.fish | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/share/functions/dirh.fish b/share/functions/dirh.fish index b75560638..5ebea4bc4 100644 --- a/share/functions/dirh.fish +++ b/share/functions/dirh.fish @@ -8,11 +8,13 @@ function dirh --description "Print the current directory history (the prev and n end set -l dirc (count $dirprev) - set -l dirprev_rev $dirprev[-1..1] - # This can't be (seq $dirc -1 1) because of BSD. - set -l dirnum (seq 1 $dirc) - for i in $dirnum[-1..1] - printf '%2d) %s\n' $i $dirprev_rev[$i] + if test $dirc -gt 0 + set -l dirprev_rev $dirprev[-1..1] + # This can't be (seq $dirc -1 1) because of BSD. + set -l dirnum (seq 1 $dirc) + for i in $dirnum[-1..1] + printf '%2d) %s\n' $i $dirprev_rev[$i] + end end echo (set_color $fish_color_history_current)' ' $PWD(set_color normal)