fork/fish-shell

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

Johannes AltmanningerMark private functions that don't need localizationa53db7256

master
1.7 KiB40 linesraw
1# localization: skip(private)
2#
3# This function only emits completions that might result from matches against $CDPATH. We rely on
4# the core file name completion logic to include all other possible matches.
5function __fish_complete_cd -d "Completions for the cd command"
6    set -q CDPATH[1]
7    or return 0 # no CDPATH so rely solely on the core file name completions
8
9    set -l token (commandline -ct)
10    if string match -qr '^\.{0,2}/.*' -- $token
11        # Absolute path or explicitly relative to the current directory. Rely on the builtin file
12        # name completions since we no longer exclude them from the `cd` argument completion.
13        return
14    end
15
16    # Relative path. Check $CDPATH and use that as the description for any possible matches.
17    # We deliberately exclude the `.` path because the core file name completion logic will include
18    # it when presenting possible matches.
19    set -l cdpath (string match -v '.' -- $CDPATH)
20
21    # Remove the CWD if it is in CDPATH since, again, the core file name completion logic will
22    # handle it.
23    set -l cdpath (string match -v -- $PWD $cdpath)
24    set -q cdpath[1]
25    or return 0
26
27    # TODO: There's a subtlety regarding descriptions - if $cdpath[1]/foo and $cdpath[2]/foo
28    # exist, we print both but want the first description to win - this currently works, but
29    # is not guaranteed.
30    for cdpath in $cdpath
31        # Replace $HOME with "~".
32        set -l desc (string replace -r -- "^$HOME" "~" "$cdpath")
33        # This assumes the CDPATH component itself is cd-able.
34        for d in $cdpath/$token*/
35            # Remove the cdpath component again.
36            test -x $d
37            and printf "%s\tCDPATH %s\n" (string replace -r "^$cdpath/" "" -- $d) $desc
38        end
39    end
40end