fork/fish-shell

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

Asuka MinatoImplement cd -L and cd -P0eb17fa58

master
1.2 KiB52 linesraw
1# localization: tier1
2#
3# Wrap the builtin cd command to maintain directory history.
4#
5function cd --description "Change directory"
6    set -l MAX_DIR_HIST 25
7
8    # Skip history in subshells.
9    if status is-command-substitution
10        builtin cd $argv
11        return $status
12    end
13
14    # Avoid set completions.
15    set -l previous $PWD
16
17    if test "$argv" = -
18        if test "$__fish_cd_direction" = next
19            nextd
20        else
21            prevd
22        end
23        return $status
24    end
25
26    builtin cd $argv
27    set -l cd_status $status
28
29    if test $cd_status -eq 0 -a "$PWD" != "$previous"
30        set -q dirprev
31        or set -l dirprev
32        set -q dirprev[$MAX_DIR_HIST]
33        and set -e dirprev[1]
34
35        # If dirprev, dirnext, __fish_cd_direction
36        # are set as universal variables, honor their scope.
37
38        set -U -q dirprev
39        and set -U -a dirprev $previous
40        or set -g -a dirprev $previous
41
42        set -U -q dirnext
43        and set -U -e dirnext
44        or set -e dirnext
45
46        set -U -q __fish_cd_direction
47        and set -U __fish_cd_direction prev
48        or set -g __fish_cd_direction prev
49    end
50
51    return $cd_status
52end