fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes AltmanningerPrepare to not localize private function descriptionsd835c5252

master
1.1 KiB45 linesraw
1# localization: tier1
2function prevd --description "Move back in the directory history"
3    set -l options h/help l/list
4    argparse -n prevd --max-args=1 $options -- $argv
5    or return
6
7    if set -q _flag_help
8        __fish_print_help prevd
9        return 0
10    end
11
12    set -l times 1
13    if set -q argv[1]
14        if test $argv[1] -ge 0 2>/dev/null
15            set times $argv[1]
16        else
17            printf (_ "%s: The number of positions to skip must be a non-negative integer\n") prevd >&2
18            return 1
19        end
20    end
21
22    # Traverse history
23    set -l code 1
24    for i in (seq $times)
25        # Try one step forward
26        if __fish_move_last dirprev dirnext
27            # We consider it a success if we were able to do at least 1 step
28            # (low expectations are the key to happiness ;)
29            set code 0
30        else
31            break
32        end
33    end
34
35    # Show history if needed
36    if set -q _flag_list
37        dirh
38    end
39
40    # Set direction for 'cd -'
41    test $code = 0
42    and set -g __fish_cd_direction next
43
44    return $code
45end