mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-12 04:58:57 +00:00
Add Makefile --file detection to completion
This commit is contained in:
parent
44e2c28255
commit
7583d57b63
2 changed files with 23 additions and 15 deletions
|
@ -1,11 +1,14 @@
|
|||
# Completions for make
|
||||
function __fish_complete_make_targets
|
||||
set directory (string replace -r '^make .*(-C ?|--directory[= ]?)([^ ]*) .*$' '$2' -- $argv)
|
||||
if test $status -eq 0 -a -d $directory
|
||||
__fish_print_make_targets $directory
|
||||
else
|
||||
__fish_print_make_targets
|
||||
set directory (string replace -r '^make .*(-C ?|--directory(=| +))([^ ]*) .*$' '$3' -- $argv)
|
||||
if not test $status -eq 0 -a -d $directory
|
||||
set directory ''
|
||||
end
|
||||
set file (string replace -r '^make .*(-f ?|--file(=| +))([^ ]*) .*$' '$3' -- $argv)
|
||||
if not test $status -eq 0 -a -f $file
|
||||
set file ''
|
||||
end
|
||||
__fish_print_make_targets "$directory" "$file"
|
||||
end
|
||||
|
||||
# This completion reenables file completion on
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
function __fish_print_make_targets --argument directory
|
||||
function __fish_print_make_targets --argument-names directory file
|
||||
# Since we filter based on localized text, we need to ensure the
|
||||
# text will be using the correct locale.
|
||||
set -lx LC_ALL C
|
||||
|
@ -7,6 +7,15 @@ function __fish_print_make_targets --argument directory
|
|||
set directory '.'
|
||||
end
|
||||
|
||||
if test -z "$file"
|
||||
for standard_file in $directory/{GNUmakefile,Makefile,makefile}
|
||||
if test -f $standard_file
|
||||
set file $standard_file
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
set -l bsd_make
|
||||
if make -C $directory -pn >/dev/null ^/dev/null
|
||||
set bsd_make 0
|
||||
|
@ -14,15 +23,11 @@ function __fish_print_make_targets --argument directory
|
|||
set bsd_make 1
|
||||
end
|
||||
|
||||
for file in $directory/{GNUmakefile,Makefile,makefile}
|
||||
if test -f $file
|
||||
if test "$bsd_make" = 0
|
||||
make -C $directory -prRn | awk -v RS= -F: '/^# Files/,/^# Finished Make data base/ {if ($1 !~ "^[#.]") {print $1}}' ^/dev/null
|
||||
else
|
||||
make -C $directory -d g1 -rn >/dev/null ^| awk -F, '/^#\*\*\* Input graph:/,/^$/ {if ($1 !~ "^#... ") {gsub(/# /,"",$1); print $1}}' ^/dev/null
|
||||
end
|
||||
break
|
||||
end
|
||||
if test "$bsd_make" = 0
|
||||
# https://stackoverflow.com/a/26339924
|
||||
make -C "$directory" -f "$file" -pRrq : ^/dev/null | awk -v RS= -F: '/^# Files/,/^# Finished Make data base/ {if ($1 !~ "^[#.]") {print $1}}' ^/dev/null
|
||||
else
|
||||
make -C "$directory" -f "$file" -d g1 -rn >/dev/null ^| awk -F, '/^#\*\*\* Input graph:/,/^$/ {if ($1 !~ "^#... ") {gsub(/# /,"",$1); print $1}}' ^/dev/null
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue