fish-shell/share/functions/nextd.fish
axel 343cafef34 Redo installation file structure, move lots of things to $PREFIX/share/fish
darcs-hash:20060217101339-ac50b-d93d2c620a4b7f75f05ff461a6edbee001da7613.gz
2006-02-17 20:13:39 +10:00

50 lines
1,022 B
Fish

function nextd -d (_ "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
# 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
# Show history if needed
if test $show_hist = 1
dirh
end
# Set direction for 'cd -'
if test $code = 0 ^/dev/null
set -g __fish_cd_direction prev
end
# All done
return $code
end