fork/fish-shell

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

Johannes Altmanninger__fish_complete_directories: remove use of empty variable13bc514aa

master
1.2 KiB29 linesraw
1# localization: skip(private)
2#
3# Find directories that complete $argv[1], output them as completions
4# with description $argv[2] if defined, otherwise use 'Directory'.
5# If no arguments are provided, attempts to complete current commandline token.
6#
7function __fish_complete_directories -d "Complete directory prefixes" --argument-names comp desc
8    if not set -q desc[1]
9        set desc Directory
10    end
11
12    if not set -q comp[1]
13        # No token given, so we use the current commandline token.
14        # If we have a --name=val option, we need to remove it,
15        # or the complete -C below would keep it, and then whatever complete
16        # called us would add it again (assuming it's in the current token)
17        set comp (commandline -ct | string replace -r -- '^-[^=]*=' '')
18    end
19
20    # HACK: We call into the file completions by using an empty command
21    # If we used e.g. `ls`, we'd run the risk of completing its options or another kind of argument.
22    # But since we default to file completions, if something doesn't have another completion...
23    # (really this should have an actual complete option)
24    set -l dirs (complete -C"'' $comp" | string match -r '.*/$')
25
26    if set -q dirs[1]
27        printf "%s\n" $dirs\t"$desc"
28    end
29end