From 4da2a2d82392d00a50117167b6321cd87bd10a41 Mon Sep 17 00:00:00 2001 From: steve Date: Wed, 21 Dec 2005 22:48:10 +0000 Subject: [PATCH] 2005-12-21 22:48:10 by steve Completion for hostnames in xen-update-image and xen-delete-image --- misc/xen-tools | 127 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 126 insertions(+), 1 deletion(-) diff --git a/misc/xen-tools b/misc/xen-tools index f96bcfc..45132a2 100644 --- a/misc/xen-tools +++ b/misc/xen-tools @@ -1,7 +1,12 @@ # # /etc/bash_completion.d/xen-tools # -# Completion functions for Bash. +# Completion functions for Bash. There is basic support for all the +# command line options, along with some specialist support to complete +# filesystem types, distribution targets and hostnames. +# +# Hostname completion will only work if 'dir=xxx' has been filled out +# within the configuration file /etc/xen-tools/xen-tools.conf # # Steve # -- @@ -68,3 +73,123 @@ complete -F _xen-create-image $filenames xen-create-image + +_xen_duplicate_image() +{ + local cur prev opts base + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + opts="--broadcast --dhcp --dir --from --gateway --help --hostname --manual --netmask --network --version" + + if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] || \ + [[ ${prev} == @(-q|--quiet) ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + fi + + # + # First of all the base directory comes from the configuration file. + # + base=`grep ^dir /etc/xen-tools/xen-tools.conf | awk -F'= ' '{print $2}'` + base=${base}/domains/ + + # + # + # + + case "${prev}" in + --from) + if [[ ${base} != '/domains/' ]] ; then + local names=$(for x in `ls -1 ${base}`; do echo ${x} ; done ) + COMPREPLY=( $(compgen -W "${names}" -- ${cur}) ) + fi + ;; + *) + COMPREPLY=($(compgen -W "${opts} -- ${cur}")) + ;; + esac +} +complete -F _xen_duplicate_image xen-duplicate-image + + + + +_xen_delete_image() +{ + local cur prev opts base + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + opts="--dir --hostname --help --manual --version" + + if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] || \ + [[ ${prev} == @(-q|--quiet) ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + fi + + # + # First of all the base directory comes from the configuration file. + # + base=`grep ^dir /etc/xen-tools/xen-tools.conf | awk -F'= ' '{print $2}'` + base=${base}/domains/ + + # + # + # + + case "${prev}" in + --hostname) + if [[ ${base} != '/domains/' ]] ; then + local names=$(for x in `ls -1 ${base}`; do echo ${x} ; done ) + COMPREPLY=( $(compgen -W "${names}" -- ${cur}) ) + fi + ;; + *) + COMPREPLY=($(compgen -W "${opts} -- ${cur}")) + ;; + esac +} +complete -F _xen_delete_image xen-delete-image + + + + +_xen_update_image() +{ + local cur prev opts base + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + opts="--dir --hostname --help --manual --version" + + if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] || \ + [[ ${prev} == @(-q|--quiet) ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + fi + + # + # First of all the base directory comes from the configuration file. + # + base=`grep ^dir /etc/xen-tools/xen-tools.conf | awk -F'= ' '{print $2}'` + base=${base}/domains/ + + # + # + # + + case "${prev}" in + --hostname) + if [[ ${base} != '/domains/' ]] ; then + local names=$(for x in `ls -1 ${base}`; do echo ${x} ; done ) + COMPREPLY=( $(compgen -W "${names}" -- ${cur}) ) + fi + ;; + *) + COMPREPLY=($(compgen -W "${opts} -- ${cur}")) + ;; + esac +} +complete -F _xen_update_image xen-update-image