From 18e903c113beafc8cb48bcb8c337d2cc9edd9cd5 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 25 Aug 2015 12:17:17 -0300 Subject: [PATCH] Bug 14727: koha-indexer tab completion in bash This patch introduces tab-completion in bash to the koha-indexer command. It completes using valid option switches and instance names. It stops completing then -h or --help are issued, and once a command switch is chosen (either --start, --stop or --restart) it goes ahead with valid instances completion. To test: - Have a packages install (kohadevbox works) - Run: $ . debian/koha-common.bash-completion - Type koha-indexer - Play with all the options => SUCCESS: They work as they should. - Sign off :-D Note: it fixes a small glitch on the plack completion. Signed-off-by: Jesse Weaver Verified working, including filtering out already used options and instances. --- debian/koha-common.bash-completion | 40 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/debian/koha-common.bash-completion b/debian/koha-common.bash-completion index d65aba2..637a56b 100644 --- a/debian/koha-common.bash-completion +++ b/debian/koha-common.bash-completion @@ -217,9 +217,9 @@ _koha-plack() --help) COMPREPLY=() ; return 0 ;; # no more completions -h) COMPREPLY=() ; return 0 ;; # no more completions --quiet) # filter the other quiet switches and go on - substract="$substract -e '--quiet' -e '-q'"; ;; + substract="$substract -e -q"; ;; -q) # filter the other quiet switches and go on - substract="$substract -e '--quiet' -e '-q'"; ;; + substract="$substract -e --quiet"; ;; esac substract="$substract -e ${COMP_WORDS[i]}" fi @@ -235,6 +235,42 @@ _koha-plack() } complete -F _koha-plack koha-plack +_koha-indexer() +{ + local cur opts substract + + COMPREPLY=() + _get_comp_words_by_ref cur + opts="--start --stop --restart --quiet -q --help -h" + + # Build a list of the already used option switches + for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do + if [[ ${COMP_WORDS[i]} == -* ]]; then + case ${COMP_WORDS[i]} in + --start) _koha_list_cmd ; return 0 ;; + --stop) _koha_list_cmd ; return 0 ;; + --restart) _koha_list_cmd ; return 0 ;; + --help) COMPREPLY=() ; return 0 ;; # no more completions + -h) COMPREPLY=() ; return 0 ;; # no more completions + --quiet) # filter the other quiet switches and go on + substract="$substract -e -q"; ;; + -q) # filter the other quiet switches and go on + substract="$substract -e --quiet"; ;; + esac + substract="$substract -e ${COMP_WORDS[i]}" + fi + done + + if [[ "$substract" != "" ]]; then + opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract ) + fi + + COMPREPLY=( $(compgen -W "$opts" -- $cur ) ) + + return 0 +} +complete -F _koha-indexer koha-indexer + # Local variables: # mode: shell-script # sh-basic-offset: 4 -- 2.5.3