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