Check for rabbitmqctl using `[ -x ]` and not `which` in autocompletion

This commit is contained in:
Daniil Fedotov 2017-01-30 17:54:41 +00:00
parent b9f2df696d
commit cd804aeb4a
3 changed files with 17 additions and 15 deletions

View File

@ -1,9 +1,11 @@
_rabbitmqctl_complete() {
if [ -x /usr/lib/rabbitmq/bin/rabbitmqctl ]; then
COMPREPLY=()
local LANG=en_US.UTF-8
local word="${COMP_WORDS[COMP_CWORD]}"
local completions="$(export LANG=en_US.UTF-8; export LC_CTYPE=en_US.UTF-8; /usr/lib/rabbitmq/bin/rabbitmqctl --auto-complete $COMP_LINE)"
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
fi
}
complete -f -F _rabbitmqctl_complete rabbitmqctl

View File

@ -1,5 +1,3 @@
if which rabbitmqctl > /dev/null; then
if [ -n "$BASH_VERSION" ]; then
if [ -n "$BASH_VERSION" ]; then
. /usr/lib/rabbitmq/autocomplete/bash_autocomplete.sh
fi
fi

View File

@ -1,10 +1,12 @@
_rabbitmqctl_complete() {
if [ -x /usr/lib/rabbitmq/bin/rabbitmqctl ]; then
local word completions a
local LANG=en_US.UTF-8
read -cl a
word="$1"
completions="$(export LANG=en_US.UTF-8; export LC_CTYPE=en_US.UTF-8; /usr/lib/rabbitmq/bin/rabbitmqctl --auto-complete ${=a})"
reply=( "${(ps:\n:)completions}" )
fi
}
compctl -f -K _rabbitmqctl_complete rabbitmqctl