- Improve Bash completion to suggest meta-packages after -i or --install options.
This commit is contained in:
@@ -28,46 +28,42 @@
|
||||
|
||||
_mpm_completion()
|
||||
{
|
||||
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
local prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
local opts="-h --help -V --version -v --verbose -T --test -l --list -i --install -r --repo"
|
||||
local mode_opts="-h --help -V --version -l --list -i --install"
|
||||
local glob_opts="-T --test -v --verbose -r --repo"
|
||||
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
local prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
|
||||
local pos=0
|
||||
local i
|
||||
local mode_set="FALSE"
|
||||
local repo=""
|
||||
local i
|
||||
|
||||
COMPREPLY=()
|
||||
|
||||
# Count non-option positional arguments already provided
|
||||
# Scan already provided words to detect mode and repo override
|
||||
for (( i=1; i<COMP_CWORD; i++ ))
|
||||
do
|
||||
case "${COMP_WORDS[i]}" in
|
||||
-h|--help|-V|--version|-v|--verbose|-T|--test|-l|--list)
|
||||
-h|--help|-V|--version|-l|--list|-i|--install)
|
||||
mode_set="TRUE"
|
||||
;;
|
||||
-i|--install|-r|--repo)
|
||||
i=$(( i + 1 ))
|
||||
;;
|
||||
--)
|
||||
;;
|
||||
-*)
|
||||
;;
|
||||
*)
|
||||
pos=$(( pos + 1 ))
|
||||
-r|--repo)
|
||||
repo="${COMP_WORDS[i+1]}"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Complete options if current word starts with '-'
|
||||
if [[ "${cur}" == -* ]]
|
||||
then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Complete based on previous option
|
||||
# Complete the argument of -i / --install with the live package list
|
||||
case "${prev}" in
|
||||
-i|--install)
|
||||
local mpm_names
|
||||
mpm_names="$(mpm --list 2>/dev/null | awk 'NR>2 { gsub(/^ +/, "", $1); print $1 }')"
|
||||
|
||||
if [[ "${repo}" != "" ]]
|
||||
then
|
||||
mpm_names="$(mpm -r "${repo}" --list 2>/dev/null | awk 'NR>2 { gsub(/^ +/, "", $1); print $1 }')"
|
||||
else
|
||||
mpm_names="$(mpm --list 2>/dev/null | awk 'NR>2 { gsub(/^ +/, "", $1); print $1 }')"
|
||||
fi
|
||||
|
||||
COMPREPLY=( $(compgen -W "${mpm_names}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
@@ -77,15 +73,13 @@ _mpm_completion()
|
||||
;;
|
||||
esac
|
||||
|
||||
# Complete positional arguments
|
||||
case "${pos}" in
|
||||
0)
|
||||
COMPREPLY=( $(compgen -W "-h --help -V --version -v --verbose -T --test -l --list -i --install -r --repo" -- "${cur}") )
|
||||
;;
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
esac
|
||||
# Build candidate list depending on whether a mode is already set
|
||||
if [[ "${mode_set}" == "TRUE" ]]
|
||||
then
|
||||
COMPREPLY=( $(compgen -W "${glob_opts}" -- "${cur}") )
|
||||
else
|
||||
COMPREPLY=( $(compgen -W "${mode_opts} ${glob_opts}" -- "${cur}") )
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user