From 641937cec6d5c11788dbd01f4fbec54de4886e32 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Tue, 3 Jan 2017 23:43:27 +0100 Subject: Reordering bash-completion to do completion the usual way (by suggesting commands first, then options and finally their arguments, rather than commands and arguments only). Signed-off-by: Daniel Baumann --- share/bash-completion/container | 210 ++++++++++++++++------------------------ 1 file changed, 81 insertions(+), 129 deletions(-) diff --git a/share/bash-completion/container b/share/bash-completion/container index 546a896..0bc22c0 100644 --- a/share/bash-completion/container +++ b/share/bash-completion/container @@ -37,243 +37,195 @@ _container() case "${cmd}" in auto) - case "${cur}" in - -*) - opts="-f --force -s --start -t --stop" - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - return 0 - ;; - esac + opts="-f --force -s --start -t --stop" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 ;; console) - case "${cur}" in - -*) - opts="-n --name" + case "${prev}" in + -n|--name) + opts=$(container list -s -f shell) COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) - case "${prev}" in - -n|--name) - opts=$(container list -s -f shell) - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - return 0 - ;; - esac + opts="-n --name" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 ;; esac ;; create) - case "${cur}" in - -*) - opts="-n --name -c --capability -d --drop-capability -s --script -b --bind" + case "${prev}" in + -n|--name) + opts=$(cd /etc/container-tools/debconf 2>/dev/null && ls *.cfg 2>/dev/null | sed -e 's/.cfg$//g') + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + ;; + + -s|--script) + opts=$(cd /usr/share/container-tools/scripts && find -maxdepth 1 -not -type d -and -not -name 'default' -and -not -name 'debconf' -and -not -name '*.d' -printf '%P\n' | sort) COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) - case "${prev}" in - -n|--name) - opts=$(cd /etc/container-tools/debconf 2>/dev/null && ls *.cfg 2>/dev/null | sed -e 's/.cfg$//g') - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - return 0 - ;; - - -s|--script) - opts=$(cd /usr/share/container-tools/scripts && find -maxdepth 1 -not -type d -and -not -name 'default' -and -not -name 'debconf' -and -not -name '*.d' -printf '%P\n' | sort) - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - return 0 - ;; - esac + opts="-n --name -c --capability -d --drop-capability -s --script -b --bind" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 ;; esac ;; enter) - case "${cur}" in - -*) - opts="-n --name" + case "${prev}" in + -n|--name) + opts=$(container list -s -f shell) COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) - case "${prev}" in - -n|--name) - opts=$(container list -s -f shell) - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - return 0 - ;; - esac + opts="-n --name" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 ;; esac ;; limit) - case "${cur}" in - -*) - opts="-n --name --blockio-device-weight --blockio-read-bandwith -b --blockio-weight --blockio-write-bandwith -c --cpu-quota --cpu-shares -m --memory-limit -t --tasks-max" + case "${prev}" in + -n|--name) + opts=$(container list -a -f shell) COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) - case "${prev}" in - -n|--name) - opts=$(container list -a -f shell) - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - return 0 - ;; - esac + opts="-n --name --blockio-device-weight --blockio-read-bandwith -b --blockio-weight --blockio-write-bandwith -c --cpu-quota --cpu-shares -m --memory-limit -t --tasks-max" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 ;; esac ;; list|ls) - case "${cur}" in - -*) - opts="-a --all -f --format -h --host -o --other -s --started -t --stopped" + case "${prev}" in + -h|--host) + opts="true false $(hostname -f)" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + ;; + + -f|--format) + opts="cli csv json nwdiag shell yaml xml" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) - case "${prev}" in - -h|--host) - opts="true false $(hostname -f)" - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - return 0 - ;; - - -f|--format) - opts="cli csv json nwdiag shell yaml xml" - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - return 0 - ;; - esac + opts="-a --all -f --format -h --host -o --other -s --started -t --stopped" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 ;; esac ;; move|mv) - case "${cur}" in - -*) - opts="-f --force -n --new -o --old" + case "${prev}" in + -o|--old) + opts=$(container list -t -f shell) COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) - case "${prev}" in - -o|--old) - opts=$(container list -t -f shell) - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - return 0 - ;; - esac + opts="-f --force -n --new -o --old" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 ;; esac ;; remove|rm) - case "${cur}" in - -*) - opts="-n --name -f --force" + case "${prev}" in + -n|--name) + opts=$(container list -t -f shell) COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) - case "${prev}" in - -n|--name) - opts=$(container list -t -f shell) - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - return 0 - ;; - esac + opts="-n --name -f --force" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 ;; esac ;; restart) - case "${cur}" in - -*) - opts="-n --name" + case "${prev}" in + -n|--name) + opts=$(container list -s -f shell) COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) - case "${prev}" in - -n|--name) - opts=$(container list -s -f shell) - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - return 0 - ;; - esac + opts="-n --name" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 ;; esac ;; start) - case "${cur}" in - -*) - opts="-n --name" + case "${prev}" in + -n|--name) + opts=$(container list -t -f shell) COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) - case "${prev}" in - -n|--name) - opts=$(container list -t -f shell) - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - return 0 - ;; - esac + opts="-n --name" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 ;; esac ;; status) - case "${cur}" in - -*) - opts="-n --name" + case "${prev}" in + -n|--name) + opts=$(container list -t -f shell) COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) - case "${prev}" in - -n|--name) - opts=$(container list -t -f shell) - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - return 0 - ;; - esac + opts="-n --name" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 ;; esac ;; stop) - case "${cur}" in - -*) - opts="-n --name -f --force" + case "${prev}" in + -n|--name) + opts=$(container list -s -f shell) COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) - case "${prev}" in - -n|--name) - opts=$(container list -s -f shell) - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - return 0 - ;; - esac + opts="-n --name -f --force" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 ;; esac ;; -- cgit v1.2.3