diff --git a/share/functions/dirh.fish b/share/functions/dirh.fish index b9b86b56b..639e920a2 100644 --- a/share/functions/dirh.fish +++ b/share/functions/dirh.fish @@ -27,7 +27,7 @@ function dirh --description "Print the current directory history (the back- and set_color normal # BSD seq 0 outputs '1 0' instead of nothing - if test (count $dirnext) -gt 0 + if count $dirnext > /dev/null for i in (seq (echo (count $dirnext)) -1 1) echo -n -e $dirnext[$i]$separator end diff --git a/share/functions/nextd.fish b/share/functions/nextd.fish index 80d7c42aa..3f28d07ac 100644 --- a/share/functions/nextd.fish +++ b/share/functions/nextd.fish @@ -12,37 +12,41 @@ function nextd --description "Move forward in the directory history" # Parse arguments set -l show_hist 0 set -l times 1 - for i in (seq (count $argv)) - switch $argv[$i] - case '-l' --l --li --lis --list - set show_hist 1 - continue - case '-*' - printf (_ "%s: Unknown option %s\n" ) nextd $argv[$i] - return 1 - case '*' - if test $argv[$i] -ge 0 ^/dev/null - set times $argv[$i] - else - printf (_ "%s: The number of positions to skip must be a non-negative integer\n" ) nextd - return 1 - end - continue - end - end + if count $argv > /dev/null + for i in (seq (count $argv)) + switch $argv[$i] + case '-l' --l --li --lis --list + set show_hist 1 + continue + case '-*' + printf (_ "%s: Unknown option %s\n" ) nextd $argv[$i] + return 1 + case '*' + if test $argv[$i] -ge 0 ^/dev/null + set times $argv[$i] + else + printf (_ "%s: The number of positions to skip must be a non-negative integer\n" ) nextd + return 1 + end + continue + end + end + end # Traverse history set -l code 1 - for i in (seq $times) - # Try one step backward - if __fish_move_last dirnext dirprev; - # We consider it a success if we were able to do at least 1 step - # (low expectations are the key to happiness ;) - set code 0 - else - break - end - end + if count $times > /dev/null + for i in (seq $times) + # Try one step backward + if __fish_move_last dirnext dirprev; + # We consider it a success if we were able to do at least 1 step + # (low expectations are the key to happiness ;) + set code 0 + else + break + end + end + end # Show history if needed if test $show_hist = 1 diff --git a/share/functions/prevd.fish b/share/functions/prevd.fish index c0361e1ff..a1e2d3d30 100644 --- a/share/functions/prevd.fish +++ b/share/functions/prevd.fish @@ -12,37 +12,41 @@ function prevd --description "Move back in the directory history" # Parse arguments set -l show_hist 0 set -l times 1 - for i in (seq (count $argv)) - switch $argv[$i] - case '-l' --l --li --lis --list - set show_hist 1 - continue - case '-*' - printf (_ "%s: Unknown option %s\n" ) prevd $argv[$i] - return 1 - case '*' - if test $argv[$i] -ge 0 ^/dev/null - set times $argv[$i] - else - printf (_ "The number of positions to skip must be a non-negative integer\n") - return 1 - end - continue - end + if count $argv > /dev/null + for i in (seq (count $argv)) + switch $argv[$i] + case '-l' --l --li --lis --list + set show_hist 1 + continue + case '-*' + printf (_ "%s: Unknown option %s\n" ) prevd $argv[$i] + return 1 + case '*' + if test $argv[$i] -ge 0 ^/dev/null + set times $argv[$i] + else + printf (_ "The number of positions to skip must be a non-negative integer\n") + return 1 + end + continue + end + end end # Traverse history set -l code 1 - for i in (seq $times) - # Try one step backward - if __fish_move_last dirprev dirnext; - # We consider it a success if we were able to do at least 1 step - # (low expectations are the key to happiness ;) - set code 0 - else - break - end - end + if count $times > /dev/null + for i in (seq $times) + # Try one step backward + if __fish_move_last dirprev dirnext; + # We consider it a success if we were able to do at least 1 step + # (low expectations are the key to happiness ;) + set code 0 + else + break + end + end + end # Show history if needed if test $show_hist = 1 @@ -57,4 +61,3 @@ function prevd --description "Move back in the directory history" # All done return $code end -