[virt-tools-list] [PATCH virt-viewer] Fixup bash completion

Jonathon Jongsma jjongsma at redhat.com
Tue May 7 16:48:16 UTC 2019


minor proposed changes
---
Although I'm not an expert in either shell scripting or bash-completion, it seems to me that this
small change accomplishes the same thing, but seems slightly cleaner? Can you see any behavior
difference with my fixup applied?

 bash-completion/virt-viewer | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/bash-completion/virt-viewer b/bash-completion/virt-viewer
index 40f6e95..fefb82a 100644
--- a/bash-completion/virt-viewer
+++ b/bash-completion/virt-viewer
@@ -13,25 +13,22 @@ _virt_viewer_complete()
     # arguments, e.g. connection URI (with the default set it's
     # split into multiple items within the array). Fortunately,
     # there's a fixup function for the array.
-    _get_comp_words_by_ref -n "\"'><=;|&(:" -w words -i cword
-    COMP_WORDS=( "${words[@]}" )
-    COMP_CWORD=${cword}
-    cur=${COMP_WORDS[$COMP_CWORD]}
+    _get_comp_words_by_ref -n "\"'><=;|&(:" -w words -i cword -c cur
 
     MODE="--name"
     ALL="--all"
     # See what URI is user trying to connect to. Honour that.
-    for ((c=1; c<=${COMP_CWORD}; c++)); do
-        case "${COMP_WORDS[c]}" in
+    for ((c=1; c<=${cword}; c++)); do
+        case "${words[c]}" in
             -c|--connect)
-                if [[ -n "${COMP_WORDS[c+1]}" ]]; then
-                    URI="${COMP_WORDS[c+1]}"
+                if [[ -n "${words[c+1]}" ]]; then
+                    URI="${words[c+1]}"
                     c=$((++c))
                 fi
                 ;;
 
             --connect=*)
-                w=${COMP_WORDS[c]#*=}
+                w=${words[c]#*=}
                 if [[ -z "$w" ]] ; then
                     return
                 fi
-- 
2.20.1




More information about the virt-tools-list mailing list