From fe7fa46d57a41bbf102fd65b8f63deca5c800c73 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Fri, 4 May 2012 18:53:38 -0700 Subject: Make dirh, nextd, prevd work on OS X --- share/functions/nextd.fish | 60 ++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 28 deletions(-) (limited to 'share/functions/nextd.fish') diff --git a/share/functions/nextd.fish b/share/functions/nextd.fish index 80d7c42a..3f28d07a 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 -- cgit v1.2.3