Created
February 2, 2020 21:22
-
-
Save memilanuk/afc2a5c724a9cd65f93c070b79f9f864 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_make is a function | |
_make () | |
{ | |
local cur prev words cword split; | |
_init_completion -s || return; | |
local file makef makef_dir=("-C" ".") makef_inc i; | |
case $prev in | |
-f | --file | --makefile | -o | --old-file | --assume-old | -W | --what-if | --new-file | --assume-new) | |
_filedir; | |
return | |
;; | |
-I | --include-dir | -C | --directory | -m) | |
_filedir -d; | |
return | |
;; | |
-E) | |
COMPREPLY=($( compgen -v -- "$cur" )); | |
return | |
;; | |
--eval | -D | -V | -x) | |
return | |
;; | |
--jobs | -j) | |
COMPREPLY=($( compgen -W "{1..$(( $(_ncpus)*2 ))}" -- "$cur" )); | |
return | |
;; | |
esac; | |
$split && return; | |
if [[ "$cur" == -* ]]; then | |
local opts="$( _parse_help "$1" )"; | |
[[ -n $opts ]] || opts="$( _parse_usage "$1" )"; | |
COMPREPLY=($( compgen -W "$opts" -- "$cur" )); | |
[[ $COMPREPLY == *= ]] && compopt -o nospace; | |
else | |
if [[ $cur == *=* ]]; then | |
prev=${cur%%=*}; | |
cur=${cur#*=}; | |
local diropt; | |
[[ ${prev,,} == *dir?(ectory) ]] && diropt=-d; | |
_filedir $diropt; | |
else | |
for ((i=0; i < ${#words[@]}; i++ )) | |
do | |
if [[ ${words[i]} == -@(C|-directory) ]]; then | |
eval makef_dir=(-C "${words[i+1]}"); | |
break; | |
fi; | |
done; | |
for ((i=0; i < ${#words[@]}; i++ )) | |
do | |
if [[ ${words[i]} == -@(f|-?(make)file) ]]; then | |
eval makef=(-f "${words[i+1]}"); | |
break; | |
fi; | |
done; | |
local mode=--; | |
if (( COMP_TYPE != 9 )); then | |
mode=-d; | |
fi; | |
local IFS=' | |
' script=$( _make_target_extract_script $mode "$cur" ); | |
COMPREPLY=($( LC_ALL=C $1 -npq __BASH_MAKE_COMPLETION__=1 "${makef[@]}" "${makef_dir[@]}" .DEFAULT 2>/dev/null | command sed -ne "$script" )); | |
if [[ $mode != -d ]]; then | |
[[ $COMPREPLY == */ ]] && compopt -o nospace; | |
fi; | |
fi; | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment