1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
# Hashbang deliberately missing because this file should be sourced, not executed
function_exists() {
declare -f -F "$1" > /dev/null
return $?
}
# Checks that bash-completion is recent enough
function_exists _get_comp_words_by_ref || return 0
_projinfo()
{
local cur prev
COMPREPLY=()
_get_comp_words_by_ref cur prev
choices=$(projinfo completion ${COMP_LINE})
if [[ "$cur" == "=" ]]; then
mapfile -t COMPREPLY < <(compgen -W "$choices" --)
elif [[ "$cur" == ":" ]]; then
mapfile -t COMPREPLY < <(compgen -W "$choices" --)
elif [[ "${cur: -1}" == "/" ]]; then
mapfile -t COMPREPLY < <(compgen -W "$choices" --)
elif [[ "${cur: -2}" == "/ " ]]; then
mapfile -t COMPREPLY < <(compgen -W "$choices" --)
elif [[ "${cur: -1}" == "+" ]]; then
mapfile -t COMPREPLY < <(compgen -W "$choices" --)
elif [[ "${cur: -2}" == "+ " ]]; then
mapfile -t COMPREPLY < <(compgen -W "$choices" --)
elif [[ "$cur" == "!" ]]; then
mapfile -t COMPREPLY < <(compgen -W "$choices" -P "! " --)
else
mapfile -t COMPREPLY < <(compgen -W "$choices" -- "$cur")
fi
for element in "${COMPREPLY[@]}"; do
if [[ $element == */ ]]; then
# Do not add a space if one of the suggestion ends with slash
compopt -o nospace
break
elif [[ $element == *= ]]; then
# Do not add a space if one of the suggestion ends with equal
compopt -o nospace
break
elif [[ $element == *: ]]; then
# Do not add a space if one of the suggestion ends with colon
compopt -o nospace
break
fi
done
}
complete -o default -F _projinfo projinfo
|