number dirh output to make prevd/nextd easier

Fixes #2786
This commit is contained in:
Kurtis Rader 2016-04-14 18:37:19 -07:00
parent 8eb342ad3c
commit f034d8ba3a

View File

@ -1,38 +1,26 @@
function dirh --description "Print the current directory history (the back- and fwd- lists)"
if count $argv >/dev/null
switch $argv[1]
case -h --h --he --hel --help
__fish_print_help dirh
return 0
end
end
# Avoid set comment
set -l current (command pwd)
set -l separator " "
set -l line_len (math (count $dirprev) + (echo $dirprev $current $dirnext | wc -m) )
if test $line_len -gt $COLUMNS
# Print one entry per line if history is long
set separator "\n"
end
for i in $dirprev
echo -n -e $i$separator
end
set_color $fish_color_history_current
echo -n -e $current$separator
set_color normal
# BSD seq 0 outputs '1 0' instead of nothing
if count $dirnext > /dev/null
for i in (seq (echo (count $dirnext)) -1 1)
echo -n -e $dirnext[$i]$separator
function dirh --description "Print the current directory history (the prev and next lists)"
if set -q argv[1]
switch $argv[1]
case -h --h --he --hel --help
__fish_print_help dirh
return 0
end
end
echo
end
set -l dirc (count $dirprev)
set -l dirprev_rev $dirprev[-1..1]
for i in (seq $dirc -1 1)
printf '%2d) %s\n' $i $dirprev_rev[$i]
end
echo (set_color $fish_color_history_current)' ' $PWD(set_color normal)
set -l dirc (count $dirnext)
if test $dirc -gt 0
for i in (seq $dirc)
printf '%2d) %s\n' $i $dirnext[$i]
end
end
echo
end