aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/completions/pushd.fish
blob: d38dc298cf5c7ae325f64cb52dad03f4fd938020 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function __fish_complete_pushd_plus
    if count $dirstack > /dev/null
        # print each member of the stack, replace $HOME with ~
        for i in (seq (count $dirstack))
            printf "+%s\t%s\n" $i "Rotate to "(string replace -r "^$HOME" "~" -- $dirstack[$i])
        end
    end
end

function __fish_complete_pushd_minus
    if count $dirstack > /dev/null
        # print each member of the stack, replace $HOME with ~
		# Negative arguments are expected to start at "-0"
        for i in (seq (count $dirstack) -1 1)
            printf "%s\t%s\n" -(math $i - 1) "Rotate to "(string replace -r "^$HOME" "~" -- $dirstack[(math -$i)])
        end
    end
end

function __fish_complete_pushd_swap
    if count $dirstack > /dev/null
        # replace $HOME with ~
        printf "\t%s\n" "Swap with "(string replace -r "^$HOME" "~" -- $dirstack[1])
    end
end

# support pushd <dir>
complete -c pushd -a "(__fish_complete_cd)"

# support pushd <>
complete -c pushd -a '(__fish_complete_pushd_swap)'

# support pushd <+n>
complete -c pushd -a '(__fish_complete_pushd_plus)'
complete -c pushd -a '(__fish_complete_pushd_minus)'