From f034d8ba3a78b544f48bb72f8db06a047481f1d2 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Thu, 14 Apr 2016 18:37:19 -0700 Subject: number `dirh` output to make prevd/nextd easier Fixes #2786 --- share/functions/dirh.fish | 50 ++++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 31 deletions(-) (limited to 'share/functions') diff --git a/share/functions/dirh.fish b/share/functions/dirh.fish index 44244e8c..942b1ed9 100644 --- a/share/functions/dirh.fish +++ b/share/functions/dirh.fish @@ -1,38 +1,26 @@ +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 -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 -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 - set_color $fish_color_history_current - echo -n -e $current$separator - set_color normal + echo (set_color $fish_color_history_current)' ' $PWD(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 + 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 + echo end - -- cgit v1.2.3