fork/fish-shell

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

Johannes Altmanningercompletions/make: fix on OpenBSD/FreeBSDd7d5d2a9b

master
2.9 KiB62 linesraw
1# Completions for make
2function __fish_print_make_targets --argument-names directory file
3    # Since we filter based on localized text, we need to ensure the
4    # text will be using the correct locale.
5    set -lx LC_ALL C
6
7    set -l makeflags -C $directory
8    if test -n "$file"
9        set -a makeflags -f $file
10    end
11
12    if make --version 2>/dev/null | string match -q 'GNU*'
13        # https://stackoverflow.com/a/26339924
14        make $makeflags -pRrq : 2>/dev/null |
15            awk -F: -v 'bs_regex=\\\\\\\\' '/^# Files/,/^# Finished Make data base/ {
16                if ($1 == "# Not a target") skip = 1;
17                if ($1 !~ "^[#.\t]" && !is_continuation ) {
18                    if (!skip) print $1;
19                    skip = 0
20                }
21                is_continuation = $0 ~ "^([^#]*[^#" bs_regex "])?(" bs_regex bs_regex ")*" bs_regex "$";
22            }' 2>/dev/null
23    else
24        # FreeBSD/NetBSD
25        make $makeflags -V .ALLTARGETS 2>/dev/null | string split ' '
26        # OpenBSD
27        or make $makeflags -d g1 -rn 2>/dev/null | awk '/^[^#. \t].+:/ { gsub(/:.*/, "", $1); print $1 }'
28    end
29end
30
31function __fish_complete_make_targets
32    set -l directory (string replace -rf '^make .*(-C ?|--directory(=| +))([^ ]*) .*$' '$3' -- $argv)
33    or set directory .
34    set -l file (string replace -rf '^make .*(-f ?|--file(=| +))([^ ]*) .*$' '$3' -- $argv)
35    __fish_print_make_targets $directory $file
36end
37
38# This completion reenables file completion on
39# assignments, so e.g. 'make foo FILES=<tab>' will receive standard
40# filename completion.
41complete -c make -n 'commandline -ct | string match -q "*=*"' -a "(__fish_complete_make_targets (commandline -p))" -d Target
42complete -f -c make -n 'commandline -ct | not string match -q "*=*"' -a "(__fish_complete_make_targets (commandline -p))" -d Target
43complete -c make -s f -d "Use file as makefile" -r
44complete -x -c make -s C -l directory -x -a "(__fish_complete_directories (commandline -ct))" -d "Change directory"
45complete -c make -s d -d "Debug mode"
46complete -c make -s e -d "Environment before makefile"
47complete -c make -s i -d "Ignore errors"
48complete -x -c make -s I -d "Search directory for makefile" -a "(__fish_complete_directories (commandline -ct))"
49complete -f -c make -s j -d "Number of concurrent jobs (no argument means no limit)"
50complete -c make -s k -d "Continue after an error"
51complete -c make -s l -d "Start when load drops"
52complete -c make -s n -d "Do not execute commands"
53complete -c make -s o -r -d "Ignore specified file"
54complete -c make -s p -d "Print database"
55complete -c make -s q -d "Question mode"
56complete -c make -s r -d "Eliminate implicit rules"
57complete -c make -s s -d "Quiet mode"
58complete -c make -s S -d "Don't continue after an error"
59complete -c make -s t -d "Touch files, don't run commands"
60complete -c make -s v -d "Display version and exit"
61complete -c make -s w -d "Print working directory"
62complete -c make -s W -r -d "Pretend file is modified"