bash-completions/rc-service: allow tab to be used again

X-Gentoo-Bug: 670290
X-Gentoo-Bug-URL: https://bugs.gentoo.org/670290
This commit is contained in:
William Hubbs 2018-12-27 16:31:15 -06:00
parent a15b532a02
commit 7e95d924c9

View File

@ -91,11 +91,14 @@ _rc_service()
done)) done))
return 0 return 0
elif [[ ${COMP_CWORD} -eq 2 ]] && [[ ${prev} != -* ]]; then # if second word typed and we didn't type in a function elif [[ ${COMP_CWORD} -eq 2 ]] && [[ ${prev} != -* ]]; then # if second word typed and we didn't type in a function
filename=$(rc-service --resolve ${prev}) rc-service --exists "$prev" || return
opts=$(cat ${filename} | grep "^\w*()" | sed "s/().*$//") # Greps the functions included in the init script shopt -s extglob
if [[ "x${opts}" == "x" ]] ; then # if no options found loosen the grep algorhythm while read -r _ line; do
opts=$(cat ${filename} | grep "\w*()" | sed "s/().*$//") if [[ $line == +([[:alnum:]_]):* ]]; then
opts+="${line%%:*} "
fi fi
done < <(rc-service "$prev" describe 2>&1)
shopt -u extglob
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0 return 0
fi fi