[Libguestfs] [PATCH] bash: complete also short options

Pino Toscano ptoscano at redhat.com
Wed Nov 26 12:06:10 UTC 2014


Propose both short and long options when trying to complete a single
dash ("-").
---
 bash/guestfish           | 8 +++++++-
 bash/guestmount          | 8 +++++++-
 bash/virt-alignment-scan | 8 +++++++-
 bash/virt-rescue         | 8 +++++++-
 bash/virt-resize         | 8 +++++++-
 5 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/bash/guestfish b/bash/guestfish
index 46d7847..eaec40f 100644
--- a/bash/guestfish
+++ b/bash/guestfish
@@ -31,7 +31,7 @@ _guestfs_virsh_list ()
 _guestfish ()
 {
     local cur prev words cword split
-    local longopts flag_ro=0 c=1 word cmds doms
+    local shortopts longopts flag_ro=0 c=1 word cmds doms
 
     _init_completion -s || return
 
@@ -61,6 +61,12 @@ _guestfish ()
             longopts="$(guestfish --long-options)"
             COMPREPLY=( $(compgen -W "$longopts" -- "$cur") )
             return ;;
+        -*)
+            # -o and --options
+            shortopts="$(guestfish --short-options)"
+            longopts="$(guestfish --long-options)"
+            COMPREPLY=( $(compgen -W "$shortopts $longopts" -- "$cur") )
+            return ;;
         *)
             # Might be a guestfish command.
             cmds=$(guestfish -h| head -n -1 | tail -n +2 | awk '{print $1}')
diff --git a/bash/guestmount b/bash/guestmount
index db79521..1bdb656 100644
--- a/bash/guestmount
+++ b/bash/guestmount
@@ -31,7 +31,7 @@ _guestfs_virsh_list ()
 _guestmount ()
 {
     local cur prev words cword split
-    local longopts flag_ro=0 c=1 word doms
+    local shortopts longopts flag_ro=0 c=1 word doms
 
     _init_completion -s || return
 
@@ -58,6 +58,12 @@ _guestmount ()
             longopts="$(guestmount --long-options)"
             COMPREPLY=( $(compgen -W "$longopts" -- "$cur") )
             return ;;
+        -*)
+            # -o and --options
+            shortopts="$(guestmount --short-options)"
+            longopts="$(guestmount --long-options)"
+            COMPREPLY=( $(compgen -W "$shortopts $longopts" -- "$cur") )
+            return ;;
         *)
             COMPREPLY=( $(compgen "$cur") )
             return ;;
diff --git a/bash/virt-alignment-scan b/bash/virt-alignment-scan
index cef8365..a2e337d 100644
--- a/bash/virt-alignment-scan
+++ b/bash/virt-alignment-scan
@@ -31,7 +31,7 @@ _guestfs_virsh_list ()
 _guestfs_virttools ()
 {
     local cur prev words cword split
-    local longopts tool="$1" flag_ro="$2" doms
+    local shortopts longopts tool="$1" flag_ro="$2" doms
 
     _init_completion -s || return
 
@@ -48,6 +48,12 @@ _guestfs_virttools ()
             longopts="$($tool --long-options)"
             COMPREPLY=( $(compgen -W "$longopts" -- "$cur") )
             return ;;
+        -*)
+            # -o and --options
+            shortopts="$($tool --short-options)"
+            longopts="$($tool --long-options)"
+            COMPREPLY=( $(compgen -W "$shortopts $longopts" -- "$cur") )
+            return ;;
         *)
             COMPREPLY=( $(compgen "$cur") )
             return ;;
diff --git a/bash/virt-rescue b/bash/virt-rescue
index bb9ca6d..da22e3c 100644
--- a/bash/virt-rescue
+++ b/bash/virt-rescue
@@ -31,7 +31,7 @@ _guestfs_virsh_list ()
 _virt_rescue ()
 {
     local cur prev words cword split
-    local longopts flag_ro=0 c=1 word doms
+    local shortopts longopts flag_ro=0 c=1 word doms
 
     _init_completion -s || return
 
@@ -58,6 +58,12 @@ _virt_rescue ()
             longopts="$(virt-rescue --long-options)"
             COMPREPLY=( $(compgen -W "$longopts" -- "$cur") )
             return ;;
+        -*)
+            # -o and --options
+            shortopts="$(virt-rescue --short-options)"
+            longopts="$(virt-rescue --long-options)"
+            COMPREPLY=( $(compgen -W "$shortopts $longopts" -- "$cur") )
+            return ;;
         *)
             COMPREPLY=( $(compgen "$cur") )
             return ;;
diff --git a/bash/virt-resize b/bash/virt-resize
index d5ac2f5..447f0cf 100644
--- a/bash/virt-resize
+++ b/bash/virt-resize
@@ -19,7 +19,7 @@
 _guestfs_options_only ()
 {
     local cur prev words cword split
-    local longopts tool="$1"
+    local shortopts longopts tool="$1"
 
     _init_completion -s || return
 
@@ -29,6 +29,12 @@ _guestfs_options_only ()
             longopts="$($tool --long-options)"
             COMPREPLY=( $(compgen -W "$longopts" -- "$cur") )
             return ;;
+        -*)
+            # -o and --options
+            shortopts="$($tool --short-options)"
+            longopts="$($tool --long-options)"
+            COMPREPLY=( $(compgen -W "$shortopts $longopts" -- "$cur") )
+            return ;;
         *)
             COMPREPLY=( $(compgen "$cur") )
             return ;;
-- 
1.9.3




More information about the Libguestfs mailing list