1 # guestfish bash completion script
2 # Copyright (C) 2010 Red Hat Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 # To use this script, copy it into /etc/bash_completion.d/ if
19 # that directory exists.
21 # If your distro does not have that directory (or if you cannot or
22 # do not want to install this in /etc) then you can copy this to
23 # somewhere in your home directory such as
24 # ~/.guestfish-bash-completion.sh and add this to your .bashrc:
25 # source ~/.guestfish-bash-completion.sh
27 # This was "inspired" by the git bash completion script written by
30 _guestfish_virsh_list ()
32 local flag_ro=$1 flags
34 if [ "$flag_ro" -eq 1 ]; then
39 virsh list $flags | head -n -1 | tail -n +3 | awk '{print $2}'
44 local flag_i=0 flag_ro=0 c=1 word cmds doms
46 # See if user has specified -i option before the current word.
47 while [ $c -lt $COMP_CWORD ]; do
48 word="${COMP_WORDS[c]}"
50 -i|--inspector) flag_i=1 ;;
56 # Now try to complete the current word.
57 word="${COMP_WORDS[COMP_CWORD]}"
60 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '
77 if [ "$flag_i" -eq 1 ]; then
78 doms=$(_guestfish_virsh_list "$flag_ro")
79 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W "$doms" -- "$word"))
81 cmds=$(guestfish -h| head -n -1 | tail -n +2 | awk '{print $1}')
82 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W "$cmds" -- "$word"))
87 complete -o bashdefault -o default -F _guestfish guestfish 2>/dev/null \
88 || complete -o default -F _guestfish guestfish