PageRenderTime 76ms CodeModel.GetById 73ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/bash_completion.d/xm

http://github.com/brinkman83/bashrc
#! | 231 lines | 220 code | 11 blank | 0 comment | 0 complexity | 87dc8377a90b2242c23a8f997ee73ab0 MD5 | raw file
  1# bash completion for xm
  2
  3have xm && {
  4_xen_domain_names()
  5{
  6    COMPREPLY=( $(compgen -W "$( xm list 2>/dev/null | \
  7        awk '!/Name|Domain-0/ { print $1 }'  )" -- "$cur") )
  8}
  9
 10_xen_domain_ids()
 11{
 12    COMPREPLY=( $(compgen -W "$( xm list 2>/dev/null | \
 13        awk '!/Name|Domain-0/ { print $2 }' )" -- "$cur") )
 14}
 15
 16_xm()
 17{
 18    # TODO: _split_longopt
 19
 20    local cur prev command options
 21
 22    COMPREPLY=()
 23    cur=`_get_cword`
 24
 25    commands='console create new delete destroy domid domname dump-core \
 26        list mem-max mem-set migrate pause reboot rename restore \
 27        resume save shutdown start suspend sysrq trigger top unpause \
 28        uptime vcpu-list vcpu-pin vcpu-set debug-keys dmesg info log \
 29        serve sched-credit sched-sedf block-attach block-detach \
 30        block-list network-attach network-detach network-list \
 31        vtpm-list vnet-list vnet-create vnet-delete labels addlabel \
 32        rmlabel getlabel dry-run resources makepolicy loadpolicy \
 33        cfgbootpolicy dumppolicy help'
 34
 35    if [[ $COMP_CWORD -eq 1 ]] ; then
 36        COMPREPLY=( $( compgen -W "$commands" -- "$cur" ) )
 37    else
 38        prev=${COMP_WORDS[COMP_CWORD-1]}
 39        if [[ "$cur" == *=* ]]; then
 40            prev=${cur/=*/}
 41            cur=${cur/*=/}
 42        fi
 43
 44        command=${COMP_WORDS[1]}
 45        if [[ "$cur" == -* ]]; then
 46            # possible options for the command
 47            case $command in
 48                create)
 49                    options='-c'
 50                    ;;
 51                dmesg)
 52                    options='--clear'
 53                    ;;
 54                list)
 55                    options='--long'
 56                    ;;
 57                reboot)
 58                    options='-w -a'
 59                    ;;
 60                shutdown)
 61                    options='-w -a -R -H'
 62                    ;;
 63                sched-credit)
 64                    options='-d -w -c'
 65                    ;;
 66                @(block|network|vtpm|vnet)-list)
 67                    options='-l --long'
 68                    ;;
 69                getpolicy)
 70                    options='--dumpxml'
 71                    ;;
 72                new)
 73                    options='-h --help --help_config -q \
 74                        --quiet --path= -f= \
 75                        --defconfig= -F= --config= \
 76                        -b --dryrun -x --xmldryrun \
 77                        -s --skipdtd -p --paused -c \
 78                        --console_autoconnect'
 79                    ;;
 80            esac
 81            COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
 82        else
 83            case $command in
 84                @(console|destroy|domname|domid|list|mem-@(set|max)|pause|reboot|rename|shutdown|unpause|vcpu-@(list|pin|set)|block-list|network-list|vtpm-list))
 85                    _count_args
 86                    case $args in
 87                        2)
 88                            _xen_domain_names
 89                            ;;
 90                    esac
 91                    ;;
 92                migrate)
 93                    _count_args
 94                        case $args in
 95                        2)
 96                            _xen_domain_names
 97                            ;;
 98                        3)
 99                            _known_hosts_real "$cur"
100                            ;;
101                    esac
102                    ;;
103                @(restore|dry-run|vnet-create))
104                    _filedir
105                    ;;
106                save)
107                    _count_args
108                    case $args in
109                        2)
110                            _xen_domain_names
111                            ;;
112                        3)
113                            _filedir
114                            ;;
115                    esac
116                    ;;
117                sysrq)
118                    _count_args
119                    case $args in
120                        2)
121                            _xen_domain_names
122                            ;;
123                        3)
124                            COMPREPLY=( $(compgen -W "r s e i u b" -- "$cur") )
125                            ;;
126                    esac
127                    ;;
128                block-attach)
129                    _count_args
130                    case $args in
131                        2)
132                            _xen_domain_names
133                            ;;
134                        3)
135                            COMPREPLY=( $(compgen -W "phy: file:" -- "$cur") )
136                            ;;
137                        5)
138                            COMPREPLY=( $(compgen -W "w r" -- "$cur") )
139                            ;;
140                        6)
141                            _xen_domain_names
142                            ;;
143                    esac
144                    ;;
145                block-detach)
146                    _count_args
147                    case $args in
148                        2)
149                            _xen_domain_names
150                            ;;
151                        3)
152                            COMPREPLY=( $(compgen -W "$( xm block-list $prev \
153                                2>/dev/null | awk '!/Vdev/ { print $1 }' )" \
154                                -- "$cur") )
155                            ;;
156                    esac
157                    ;;
158                network-attach)
159                    _count_args
160                    case $args in
161                        2)
162                            _xen_domain_names
163                            ;;
164                        *)
165                            COMPREPLY=( $(compgen -W "script= ip= mac= \
166                                bridge= backend=" -- "$cur") )
167                            ;;
168                    esac
169                    ;;
170                network-detach)
171                    _count_args
172                    case $args in
173                        2)
174                            _xen_domain_names
175                            ;;
176                        3)
177                            COMPREPLY=( $(compgen -W "$( xm network-list $prev \
178                                2>/dev/null | awk '!/Idx/ { print $1 }' )" \
179                                -- "$cur") )
180                            ;;
181                    esac
182                    ;;
183                sched-credit)
184                    case $prev in
185                        -d)
186                            _xen_domain_names
187                            return 0
188                            ;;
189                    esac
190                    ;;
191                create)
192                    _filedir
193                    COMPREPLY=( ${COMPREPLY[@]:-} \
194                        $( compgen -W '$( command ls /etc/xen 2>/dev/null )' \
195                        -- "$cur" ) )
196                    ;;
197                new)
198                    case $prev in
199                        -@(f|F|-defconfig|-config))
200                            _filedir
201                            return 0
202                            ;;
203                        --path)
204                            _filedir -d
205                            return 0
206                            ;;
207                    esac
208
209                    _count_args
210                        case $args in
211                        2)
212                            _xen_domain_names
213                            ;;
214                    esac
215                    ;;
216            esac
217        fi
218    fi
219
220    return 0
221}
222complete -F _xm xm
223}
224
225# Local variables:
226# mode: shell-script
227# sh-basic-offset: 4
228# sh-indent-comment: t
229# indent-tabs-mode: nil
230# End:
231# ex: ts=4 sw=4 et filetype=sh