Closes Alioth #311614 Globbing might occur if $cur contains one of these globbing characters: * ? [ ] The bug becomes apparent: On Cygwin if the glob-string contains backslashes as well, causing a warning (Cygwin >= 1.7): MS-DOS style path detected: ... Preferred POSIX equivalent is: ... CYGWIN environment variable option "nodosfilewarning" turns off this warning. Consult the user's guide for more details about POSIX paths: http://cygwin.com/cygwin-ug-net/using.html#using-pathnames On Linux, using strace, you can see bash-completion doing an unnecessary `open' system call. Steps to reproduce on Linux using `strace': Environment: Linux, bash-completion-1.0 1. Start bash with bash-completion loaded and find out PID ($$): $ echo $$ MYPID 2. In a second bash shell, `strace' the above PID: $ strace -e trace=open -f -o strace.log -p MYPID 3. Within the first bash shell, type: $ cur="?"; _kernel_versions 4. In the second bash shell, type ^C to quick `strace'. 5. Check `strace.log', here you can see bash accessing something it shouldn't: ... open(".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 3 ... 6. The above call to `open' disappears if $cur in _kernel_versions gets quoted, and you repeat the steps above: _kernel_versions() { COMPREPLY=( $( compgen -W '$( command ls /lib/modules )' -- "$cur" ) ) }
75 lines
2.0 KiB
Bash
75 lines
2.0 KiB
Bash
# -*- mode: shell-script; sh-basic-offset: 8; indent-tabs-mode: t -*-
|
|
# ex: ts=8 sw=8 noet filetype=sh
|
|
#
|
|
# bash completion for GNU make
|
|
|
|
have make || have gmake || have gnumake || have pmake &&
|
|
_make()
|
|
{
|
|
local file makef makef_dir="." makef_inc cur prev i split=false
|
|
|
|
COMPREPLY=()
|
|
cur=`_get_cword`
|
|
prev=${COMP_WORDS[COMP_CWORD-1]}
|
|
|
|
_split_longopt && split=true
|
|
|
|
case $prev in
|
|
-@(f|o|W|-@(?(make|old-|new-)file|assume-@(old|new)|what-if)))
|
|
_filedir
|
|
return 0
|
|
;;
|
|
-I|-C|--directory|--include-dir)
|
|
_filedir -d
|
|
return 0
|
|
;;
|
|
esac
|
|
|
|
$split && return 0
|
|
|
|
if [[ "$cur" == -* ]]; then
|
|
COMPREPLY=( $( compgen -W '-b -m -B -C -d -e -f -h -i -I\
|
|
-j -l -k -n -o -p -q -r -R - s -S -t -v -w -W \
|
|
--always-make --directory --debug \
|
|
--environment-overrides --file --makefile --help \
|
|
--ignore-errors --include-dir --jobs --load-average \
|
|
--max-load --keep-going --just-print --dry-run \
|
|
--recon --old-file --assume-old --print-data-base \
|
|
--question --no-builtin-rules --no-builtin-variables \
|
|
--silent --quiet --no-keep-goind --stop --touch \
|
|
--version --print-directory --no-print-directory \
|
|
--what-if --new-file --assume-new \
|
|
--warn-undefined-variables' -- "$cur" ) )
|
|
else
|
|
# before we check for makefiles, see if a path was specified
|
|
# with -C
|
|
for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do
|
|
if [[ ${COMP_WORDS[i]} == -C ]]; then
|
|
# eval for tilde expansion
|
|
eval makef_dir=${COMP_WORDS[i+1]}
|
|
break
|
|
fi
|
|
done
|
|
|
|
# before we scan for targets, see if a Makefile name was
|
|
# specified with -f
|
|
for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do
|
|
if [[ ${COMP_WORDS[i]} == -f ]]; then
|
|
# eval for tilde expansion
|
|
eval makef=${COMP_WORDS[i+1]}
|
|
break
|
|
fi
|
|
done
|
|
|
|
[ -n "$makef" ] && makef="-f ${makef}"
|
|
[ -n "$makef_dir" ] && makef_dir="-C ${makef_dir}"
|
|
|
|
COMPREPLY=( $( compgen -W "$( make -qp $makef $makef_dir 2>/dev/null | \
|
|
awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ \
|
|
{split($1,A,/ /);for(i in A)print A[i]}' )" \
|
|
-- "$cur" ) )
|
|
|
|
fi
|
|
} &&
|
|
complete -F _make $filenames make gmake gnumake pmake
|