1
0
mirror of synced 2026-02-12 10:27:13 +00:00
Files
xen-tools.xen-tools/misc/xen-tools
steve 1f43abdd02 2005-12-23 00:30:37 by steve
1.  Complete IP address partially.
  2.  Add '--ip' completion to xen-duplicate-image.
2005-12-23 00:30:37 +00:00

220 lines
5.3 KiB
Plaintext

#
# /etc/bash_completion.d/xen-tools
#
# 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
#
# Reference page: http://dev.gentoo.org/~plasmaroo/devmanual/tasks-reference/completion/
# Steve
# --
# http://www.steve.org.uk
#
# $Id: xen-tools,v 1.9 2005-12-23 00:30:37 steve Exp $
#
#
# Completion for xen-create-image
#
# Completes the command line flags, and will allow tab completion of
# the supported filesystems
#
_xen-create-image()
{
local cur prev i exprfound onlyonce
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
#
# Complete the initial part of the IP in the configuration file.
ip=`grep ^gateway /etc/xen-tools/xen-tools.conf | awk -F'= ' '{print $2}'`
case "$prev" in
--fs)
COMPREPLY=( $( compgen -W 'xfs ext3 reiserfs' -- \
"${COMP_WORDS[COMP_CWORD]}" ) )
return 0
;;
--dist)
COMPREPLY=( $( compgen -W 'sid sarge etch' -- \
"${COMP_WORDS[COMP_CWORD]}" ) )
return 0
;;
--ip)
ip=`echo ${ip} | sed -e 's/[.][^.]*$/./'`
COMPREPLY=( $(compgen -W "${ip}" -- ${cur}) )
return 0
;;
esac
_expand || return 0
# complete using basic options
COMPREPLY=( $( compgen -W '--broadcast --boot --debug --debootstrap --dhcp --dir --dist --fs --gateway --help --hostname --ip --manual --memory --mirror --size --swap --version' -- $cur ) )
COMPREPLY=( $( echo "${COMP_WORDS[@]}" | \
(while read -d ' ' i; do
[ "$i" == "" ]
continue
# flatten array with spaces on either side,
# otherwise we cannot grep on word boundaries of
# first and last word
COMPREPLY=" ${COMPREPLY[@]} "
# remove word from list of completions
COMPREPLY=( ${COMPREPLY/ ${i%% *} / } )
done
echo ${COMPREPLY[@]})
) )
_filedir
return 0
}
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 --ip --manual --version"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] || \
[[ ${prev} == @(-q|--quiet) ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
#
# Complete the initial part of the IP in the configuration file.
ip=`grep ^gateway /etc/xen-tools/xen-tools.conf | awk -F'= ' '{print $2}'`
#
# 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
return 0
;;
--ip)
ip=`echo ${ip} | sed -e 's/[.][^.]*$/./'`
COMPREPLY=( $(compgen -W "${ip}" -- ${cur}) )
return 0
;;
*)
COMPREPLY=($(compgen -W "${opts} -- ${cur}"))
return 0
;;
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