Zshell auto completion for lxc
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

188 lines
6.2 KiB

# vim:ft=zsh ts=2 sw=2 sts=2
#compdef lxc-start lxc-stop lxc-restart lxc-create lxc-destroy lxc-monitor lxc-console lxc-ls lxc-top lxc-cgroup lxc-checkpoint lxc-execute lxc-attach lxc-freeze lxc-unfreeze lxc-info lxc-wait lxc-snapshot
##########################################
#Copyright (c) 2016 Blagovest Petrov <blagovest@petrovs.info>
# Based on the work of Vincent Rischmann - https://lists.linuxcontainers.org/pipermail/lxc-devel/2010-April/001172.html
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
##########################################
_lxc_containers() {
local -a containers
containers=( $(/usr/bin/lxc-ls) )
compadd "$@" -a containers
}
_lxc_sortby(){
local -a sortby
sortby=(n c b m k)
compadd "$@" -a sortby
}
_lxc_name_opt=(
'(-n --name)'{-n,--name=}'[Name of the container]:name:_lxc_containers'
)
_lxc_console_opts=(
'(-e --escape)'{-e,--escape=}'[Escape character. Specify the escape sequence prefix to use instead of <Ctrl a>.]'
'(-t --tty)'{-t,--tty=}'[Console TTY number. Specify the tty number to connect to or 0 for the console.]'
)
_lxc_start_opts=(
'(-d --daemon)'{-d,--daemon}'[Daemonize the container]'
'(-f --rcfile)'{-f,--rcfile=}'[Load configuration file FILE]:config:_files'
'(-s --define)'{-s,--define}'[Assign VAL to configuration variable KEY]'
)
_lxc_restart_opts=(
'(-p --pause)'{-p,--pause}'[Do not release the container after the restart]'
'(-d --directory)'{-d,--directory=}'[Name of statefile]:name:_files'
'(-f --rcfile)'{-f,--rcfile=}'[Load configuration file FILE]:config:_files'
'(-s --define)'{-s,--define}'[Assign VAL to configuration variable KEY]'
)
_lxc_create_opts=(
'(-n --name)'{-n,--name=}'[Name of the container]:name'
'(-f --config)'{-f,--config=}'[Load configuration file FILE]:config:_files'
'(-t --template)'{-t,--template=}'[LXC template script]:tpl:_files'
'(-h --help)'{-h,--help}'[Print Help ]'
)
_lxc_checkpoint_opts=(
'(-k --kill)'{-k,--kill}'[Stop the container after the checkpoint]'
'(-p --pause)'{-p,--pause}'[Dont unfreeze the container after the checkpoint]'
'(-d --directory)'{-d,--directory=}'[Where to store the statefile]:statefile:_files'
)
_lxc_execute_opts=(
'(-f --rcfile)'{-f,--rcfile=}'[Load configuration file FILE]:config:_files'
'(-s --define)'{-s,--define}'[Assign VAL to configuration variable KEY]'
)
_lxc_wait_opts=(
'(-s --state)'{-s,--state=}'[ORed states to wait for: STOPPED, STARTING, RUNNING, STOPPING, ABORTING, FREEZING, FROZEN]:state'
)
_lxc_ls_opts=(
'-1[Show one entry per line]'
'--active[List only active containers (same as --frozen --running)]'
'--frozen[List only frozen containers]'
'--runing[List only running containers]'
'--stopped[List only stopped containers]'
'--fancy[list all the containers, listing one per line along with its name, state, ipv4 and ipv6 address-es]'
)
_lxc_top_opts=(
'(-d, --delay)'{-d, --delay}'[Amount of time in seconds to delay between screen updates]'
'(-s, --sort)'{-s, --sort}'[Sort the containers by name, cpu use, or memory use. The sortby argument should be one of the letters n,c,b,m,k to sort by name, cpu use, block I/O, memory, or kernel memory use respective-ly. The default is "n".]:name:_lxc_sortby'
'(-r, --reverse)'{-r, --reverse}'[Reverse the default sort order]'
)
_lxc_common_opts=(
'(-o --logfile)'{-o,--logfile=}'[Output log to FILE instead of stderr]:logfile:_files'
'(-l --logpriority)'{-l,--logpriority=}'[Set log priority to LEVEL]:level:'
'(-q --quiet)'{-q,--quiet}'[Dont produce any output]'
'(-h --help)'{-h,--help}'[Help list]'
'--version[Shows the Lxc version number]'
'--usage[Give a short usage message]'
)
_lxc() {
case "$service" in
lxc-start)
_arguments -s : \
"$_lxc_name_opt[@]" \
"$_lxc_start_opts[@]" \
"$_lxc_common_opts[@]"
;;
lxc-stop)
_arguments -s : \
"$_lxc_name_opt[@]" \
"$_lxc_common_opts[@]" \
;;
lxc-console)
_arguments -s : \
"$_lxc_name_opt[@]" \
"$_lxc_console_opts[@]" \
"$_lxc_common_opts[@]"
;;
lxc-restart)
_arguments -s : \
"$_lxc_name_opt[@]" \
"$_lxc_restart_opts[@]" \
"$_lxc_common_opts[@]"
;;
lxc-create)
_arguments -s : "$_lxc_create_opts[@]"
;;
lxc-destroy)
_arguments -s : "$_lxc_name_opt[@]"
;;
lxc-monitor)
_arguments -s : \
"$_lxc_name_opt[@]" \
"$_lxc_common_opts[@]"
;;
lxc-cgroup)
_arguments -s : \
"$_lxc_name_opt[@]" \
"$_lxc_common_opts[@]"
;;
lxc-checkpoint)
_arguments -s : \
"$_lxc_name_opt[@]" \
"$_lxc_checkpoint_opts[@]" \
"$_lxc_common_opts[@]"
;;
lxc-execute)
_arguments -s : \
"$_lxc_name_opt[@]" \
"$_lxc_execute_opts[@]" \
"$_lxc_common_opts[@]"
;;
lxc-freeze)
_arguments -s : \
"$_lxc_name_opt[@]" \
"$_lxc_common_opts[@]"
;;
lxc-unfreeze)
_arguments -s : \
"$_lxc_name_opt[@]" \
"$_lxc_common_opts[@]"
;;
lxc-info)
_arguments -s : \
"$_lxc_name_opt[@]" \
"$_lxc_common_opts[@]"
;;
lxc-wait)
_arguments -s : \
"$_lxc_name_opt[@]" \
"$_lxc_wait_opts[@]"
;;
lxc-ls)
_arguments -s : \
"$_lxc_ls_opts[@]"
;;
lxc-top)
_arguments -s : \
"$_lxc_top_opts[$]"
;;
lxc-snapshot)
_arguments -s : \
"$_lxc_name_opt[@]" \
"$_lxc_common_opts[@]"
;;
*)
return 1
esac
}
_lxc "$@"