Bug 14714: Add tab-completion to koha-mysql command
authorTomas Cohen Arazi <tomascohen@theke.io>
Mon, 24 Aug 2015 18:44:22 +0000 (15:44 -0300)
committerTomas Cohen Arazi <tomascohen@theke.io>
Wed, 26 Aug 2015 13:44:01 +0000 (10:44 -0300)
This patch introduces tab-completion in bash to the koha-mysql
command. It completes using valid instance names. It stops completing
once an instance name is chosen (i.e. it respects the fact that
koha-mysql accepts only one instance name as parameter).

To test:
- Have a packages install (kohadevbox works)
- Run:
  $ . debian/koha-common.bash-completion
- Type
  koha-mysql <tab>
=> SUCCESS: You are prompted valid instance names for completion.
- Sign off :-D

Signed-off-by: Nick Clemens <nick@quecheelibrary.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

debian/koha-common.bash-completion

index 07bcdc1..d65aba2 100644 (file)
@@ -43,6 +43,21 @@ _build_substract_instances()
     echo "$substract"
 }
 
+_koha_single_instance()
+{
+    local filter=$1
+
+    cur=${COMP_WORDS[COMP_CWORD]}
+    prev=${COMP_WORDS[COMP_CWORD-1]}
+    if [ $COMP_CWORD -eq 1 ]; then
+        COMPREPLY=( $( compgen -W "$(koha-list $filter)" $cur ) )
+    else
+        COMPREPLY=()
+    fi
+
+    return 0
+}
+
 _koha_list_cmd()
 {
     local filter=$1
@@ -120,6 +135,9 @@ complete -F _koha_enabled_instances koha-start-zebra
 complete -F _koha_enabled_instances koha-restart-zebra
 complete -F _koha_enabled_instances koha-stop-zebra
 
+# koha-mysql autocompletes with a single instance name
+complete -F _koha_single_instance koha-mysql
+
 _koha_list()
 {
     local cur opts substract