From 1784cd26330481814916e3bd961f9d66030aac46 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Tue, 25 Nov 2014 18:36:14 +0100 Subject: [PATCH] bash: complete also short options 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 46d78475e..eaec40f69 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 db79521e8..1bdb6564f 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 cef8365c3..a2e337dcf 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 bb9ca6db8..da22e3c84 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 d5ac2f569..447f0cf87 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 ;;