mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-26 03:35:17 +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
|
# Completions for make
|
||||||
function __fish_complete_make_targets
|
function __fish_complete_make_targets
|
||||||
set directory (string replace -r '^make .*(-C ?|--directory[= ]?)([^ ]*) .*$' '$2' -- $argv)
|
set directory (string replace -r '^make .*(-C ?|--directory(=| +))([^ ]*) .*$' '$3' -- $argv)
|
||||||
if test $status -eq 0 -a -d $directory
|
if not test $status -eq 0 -a -d $directory
|
||||||
__fish_print_make_targets $directory
|
set directory ''
|
||||||
else
|
|
||||||
__fish_print_make_targets
|
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
# This completion reenables file completion on
|
# 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
|
# Since we filter based on localized text, we need to ensure the
|
||||||
# text will be using the correct locale.
|
# text will be using the correct locale.
|
||||||
set -lx LC_ALL C
|
set -lx LC_ALL C
|
||||||
|
@ -7,6 +7,15 @@ function __fish_print_make_targets --argument directory
|
||||||
set directory '.'
|
set directory '.'
|
||||||
end
|
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
|
set -l bsd_make
|
||||||
if make -C $directory -pn >/dev/null ^/dev/null
|
if make -C $directory -pn >/dev/null ^/dev/null
|
||||||
set bsd_make 0
|
set bsd_make 0
|
||||||
|
@ -14,15 +23,11 @@ function __fish_print_make_targets --argument directory
|
||||||
set bsd_make 1
|
set bsd_make 1
|
||||||
end
|
end
|
||||||
|
|
||||||
for file in $directory/{GNUmakefile,Makefile,makefile}
|
if test "$bsd_make" = 0
|
||||||
if test -f $file
|
# https://stackoverflow.com/a/26339924
|
||||||
if test "$bsd_make" = 0
|
make -C "$directory" -f "$file" -pRrq : ^/dev/null | awk -v RS= -F: '/^# Files/,/^# Finished Make data base/ {if ($1 !~ "^[#.]") {print $1}}' ^/dev/null
|
||||||
make -C $directory -prRn | awk -v RS= -F: '/^# Files/,/^# Finished Make data base/ {if ($1 !~ "^[#.]") {print $1}}' ^/dev/null
|
else
|
||||||
else
|
make -C "$directory" -f "$file" -d g1 -rn >/dev/null ^| awk -F, '/^#\*\*\* Input graph:/,/^$/ {if ($1 !~ "^#... ") {gsub(/# /,"",$1); print $1}}' ^/dev/null
|
||||||
make -C $directory -d g1 -rn >/dev/null ^| awk -F, '/^#\*\*\* Input graph:/,/^$/ {if ($1 !~ "^#... ") {gsub(/# /,"",$1); print $1}}' ^/dev/null
|
|
||||||
end
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue