Skip to content

Instantly share code, notes, and snippets.

@linux-china
Last active April 20, 2023 07:48
Show Gist options
  • Save linux-china/3e1a7ce99393382ad8fe575af19c8f07 to your computer and use it in GitHub Desktop.
Save linux-china/3e1a7ce99393382ad8fe575af19c8f07 to your computer and use it in GitHub Desktop.
multipass shell completion for zsh & bash
complete -c multipass -n "__fish_use_subcommand" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_use_subcommand" -s V -l version -d 'Prints version information'
complete -c multipass -n "__fish_use_subcommand" -f -a "delete" -d 'Delete instances'
complete -c multipass -n "__fish_use_subcommand" -f -a "exec" -d 'Run a command on an instance'
complete -c multipass -n "__fish_use_subcommand" -f -a "find" -d 'Display available images to create instances from'
complete -c multipass -n "__fish_use_subcommand" -f -a "get" -d 'Get a configuration setting'
complete -c multipass -n "__fish_use_subcommand" -f -a "help" -d 'Display help about a command'
complete -c multipass -n "__fish_use_subcommand" -f -a "info" -d 'Display information about instances'
complete -c multipass -n "__fish_use_subcommand" -f -a "launch" -d 'Create and start an Ubuntu instance'
complete -c multipass -n "__fish_use_subcommand" -f -a "list" -d 'List all available instances'
complete -c multipass -n "__fish_use_subcommand" -f -a "mount" -d 'Mount a local directory in the instance'
complete -c multipass -n "__fish_use_subcommand" -f -a "purge" -d 'Purge all deleted instances permanently'
complete -c multipass -n "__fish_use_subcommand" -f -a "recover" -d 'Recover deleted instances'
complete -c multipass -n "__fish_use_subcommand" -f -a "restart" -d 'Restart instances'
complete -c multipass -n "__fish_use_subcommand" -f -a "set" -d 'Set a configuration setting'
complete -c multipass -n "__fish_use_subcommand" -f -a "shell" -d 'Open a shell on a running instance'
complete -c multipass -n "__fish_use_subcommand" -f -a "start" -d 'Start instances'
complete -c multipass -n "__fish_use_subcommand" -f -a "stop" -d 'Stop running instances'
complete -c multipass -n "__fish_use_subcommand" -f -a "suspend" -d 'Suspend running instances'
complete -c multipass -n "__fish_use_subcommand" -f -a "transfer" -d 'Transfer files between the host and instances'
complete -c multipass -n "__fish_use_subcommand" -f -a "umount" -d 'Unmount a directory from an instance'
complete -c multipass -n "__fish_use_subcommand" -f -a "version" -d 'Show version details'
complete -c multipass -n "__fish_seen_subcommand_from delete" -d 'Names of instances to delete' -r
complete -c multipass -n "__fish_seen_subcommand_from delete" -l all -d 'Delete all instances'
complete -c multipass -n "__fish_seen_subcommand_from delete" -s p -l purge -d 'Purge instances immediately'
complete -c multipass -n "__fish_seen_subcommand_from delete" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_seen_subcommand_from delete" -s V -l version -d 'Prints version information'
complete -c multipass -n "__fish_seen_subcommand_from exec" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_seen_subcommand_from exec" -s V -l version -d 'Prints version information'
complete -c multipass -n "__fish_seen_subcommand_from find" -d ' An optional value to search for in [<remote:>]<string>' -r
complete -c multipass -n "__fish_seen_subcommand_from find" -l format -d 'Output list in the requested format.Valid formats are: table (default), json, csv and yaml'
complete -c multipass -n "__fish_seen_subcommand_from find" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_seen_subcommand_from find" -s V -l version -d 'Prints version information'
complete -c multipass -n "__fish_seen_subcommand_from get" -d ' Path to the setting whose configured value should be obtained.' -r
complete -c multipass -n "__fish_seen_subcommand_from get" -l raw -d 'Output in raw format. For now, this affects only the representation of empty values (i.e. "" instead of "<empty>").'
complete -c multipass -n "__fish_seen_subcommand_from get" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_seen_subcommand_from get" -s V -l version -d 'Prints version information'
complete -c multipass -n "__fish_seen_subcommand_from help" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_seen_subcommand_from help" -s V -l version -d 'Prints version information'
complete -c multipass -n "__fish_seen_subcommand_from info" -d ' Names of instances to display information about' -r
complete -c multipass -n "__fish_seen_subcommand_from info" -l all -d 'Display info for all instances'
complete -c multipass -n "__fish_seen_subcommand_from info" -l format -d 'Output info in the requested format. Valid formats are: table (default), json, csv and yaml'
complete -c multipass -n "__fish_seen_subcommand_from info" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_seen_subcommand_from info" -s V -l version -d 'Prints version information'
complete -c multipass -n "__fish_seen_subcommand_from launch" -s c -l cpus -d 'Number of CPUs to allocate. Minimum: 1, default: 1.' -r
complete -c multipass -n "__fish_seen_subcommand_from launch" -s m -l mem -d 'Amount of memory to allocate. Positive integers, in bytes, or with K, M, G suffix. Minimum: 128M, default: 1G.' -r
complete -c multipass -n "__fish_seen_subcommand_from launch" -s d -l disk -d 'Disk space to allocate. Positive integers, in bytes, or with K, M, G suffix. Minimum: 512M, default: 5G.' -r
complete -c multipass -n "__fish_seen_subcommand_from launch" -s n -l name -d 'Name for the instance. If it is primary (the configured primary instance name), the user home directory is mounted inside the newly launched instance, in Home.' -r
complete -c multipass -n "__fish_seen_subcommand_from launch" -d 'Optional image to launch. If omitted, then the default Ubuntu LTS will be used.' -r
complete -c multipass -n "__fish_seen_subcommand_from launch" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_seen_subcommand_from launch" -s V -l version -d 'Prints version information'
complete -c multipass -n "__fish_seen_subcommand_from list" -l format -d 'Output list in the requested format. Valid formats are: table (default), json, csv and yaml'
complete -c multipass -n "__fish_seen_subcommand_from list" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_seen_subcommand_from list" -s V -l version -d 'Prints version information'
complete -c multipass -n "__fish_seen_subcommand_from mount" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_seen_subcommand_from mount" -s V -l version -d 'Prints version information'
complete -c multipass -n "__fish_seen_subcommand_from purge" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_seen_subcommand_from purge" -s V -l version -d 'Prints version information'
complete -c multipass -n "__fish_seen_subcommand_from recover" -d 'Names of instances to recover' -r
complete -c multipass -n "__fish_seen_subcommand_from recover" -l all -d 'Recover all deleted instances'
complete -c multipass -n "__fish_seen_subcommand_from recover" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_seen_subcommand_from recover" -s V -l version -d 'Prints version information'
complete -c multipass -n "__fish_seen_subcommand_from restart" -d 'Names of instances to restart. If omitted, and without the --all option, primary will be assumed.' -r
complete -c multipass -n "__fish_seen_subcommand_from restart" -l all -d 'Recover all deleted instances'
complete -c multipass -n "__fish_seen_subcommand_from restart" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_seen_subcommand_from restart" -s V -l version -d 'Prints version information'
complete -c multipass -n "__fish_seen_subcommand_from set" -d 'A key-value pair. The key specifies a path to the setting to configure. The value is its intended value.' -r
complete -c multipass -n "__fish_seen_subcommand_from set" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_seen_subcommand_from set" -s V -l version -d 'Prints version information'
complete -c multipass -n "__fish_seen_subcommand_from shell" -d 'Name of the instance to open a shell on. If omitted, primary (the configured primary instance name) will be assumed. If the instance is not running, an attempt is made to start it (see `start` for more info).' -r
complete -c multipass -n "__fish_seen_subcommand_from shell" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_seen_subcommand_from shell" -s V -l version -d 'Prints version information'
complete -c multipass -n "__fish_seen_subcommand_from start" -d 'Names of instances to start. If omitted, and without the --all option, primary (the configured primary instance name) will be assumed. If primary does not exist but is included in a successful start command (either implicitly or explicitly), it is launched automatically (see `launch` for more info).' -r
complete -c multipass -n "__fish_seen_subcommand_from start" -l all -d 'Start all instances'
complete -c multipass -n "__fish_seen_subcommand_from start" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_seen_subcommand_from start" -s V -l version -d 'Prints version information'
complete -c multipass -n "__fish_seen_subcommand_from stop" -s t -l time -d 'Time from now, in minutes, to delay shutdown of the instance' -r
complete -c multipass -n "__fish_seen_subcommand_from stop" -s c -l cancel -d 'Cancel a pending delayed shutdown' -r
complete -c multipass -n "__fish_seen_subcommand_from stop" -d 'Names of instances to stop. If omitted, and without the --all option, primary will be assumed' -r
complete -c multipass -n "__fish_seen_subcommand_from stop" -l all -d 'Stop all instances'
complete -c multipass -n "__fish_seen_subcommand_from stop" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_seen_subcommand_from stop" -s V -l version -d 'Prints version information'
complete -c multipass -n "__fish_seen_subcommand_from suspend" -d 'Names of instances to suspend. If omitted, and without the --all option, primary will be assumed.' -r
complete -c multipass -n "__fish_seen_subcommand_from suspend" -l all -d 'Suspend all instances'
complete -c multipass -n "__fish_seen_subcommand_from suspend" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_seen_subcommand_from suspend" -s V -l version -d 'Prints version information'
complete -c multipass -n "__fish_seen_subcommand_from transfer" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_seen_subcommand_from transfer" -s V -l version -d 'Prints version information'
complete -c multipass -n "__fish_seen_subcommand_from umount" -d 'Mount points, in <name>[:<path>] format, where <name> are instance names, and optional <path> are mount points. If omitted, all mounts will be removed from the named instances.' -r
complete -c multipass -n "__fish_seen_subcommand_from umount" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_seen_subcommand_from umount" -s V -l version -d 'Prints version information'
complete -c multipass -n "__fish_seen_subcommand_from version" -s h -l help -d 'Prints help information'
complete -c multipass -n "__fish_seen_subcommand_from version" -s V -l version -d 'Prints version information'
_multipass() {
local i cur prev opts cmds
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
cmd=""
opts=""
for i in ${COMP_WORDS[@]}
do
case "${i}" in
multipass)
cmd="multipass"
;;
delete)
cmd+="__delete"
;;
exec)
cmd+="__exec"
;;
find)
cmd+="__find"
;;
get)
cmd+="__get"
;;
help)
cmd+="__help"
;;
info)
cmd+="__info"
;;
launch)
cmd+="__launch"
;;
list)
cmd+="__list"
;;
mount)
cmd+="__mount"
;;
purge)
cmd+="__purge"
;;
recover)
cmd+="__recover"
;;
restart)
cmd+="__restart"
;;
set)
cmd+="__set"
;;
shell)
cmd+="__shell"
;;
start)
cmd+="__start"
;;
stop)
cmd+="__stop"
;;
suspend)
cmd+="__suspend"
;;
transfer)
cmd+="__transfer"
;;
umount)
cmd+="__umount"
;;
version)
cmd+="__version"
;;
*)
;;
esac
done
case "${cmd}" in
multipass)
opts=" -h -V --help --version delete exec find get help info launch list mount purge recover restart set shell start stop suspend transfer umount version"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
multipass__delete)
opts=" -p -h -V --all --purge --help --version <name> "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
multipass__exec)
opts=" -h -V --help --version <name> <command> "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
multipass__find)
opts=" -h -V --format --help --version <string> "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
multipass__get)
opts=" -h -V --raw --help --version <key> "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
multipass__help)
opts=" -h -V --help --version "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
multipass__info)
opts=" -h -V --all --format --help --version <name> "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
multipass__launch)
opts=" -c -m -d -n -h -V --cpus --mem --disk --name --help --version <image> "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
--cpus)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
-c)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--mem)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
-m)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--disk)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
-d)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--name)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
-n)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
multipass__list)
opts=" -h -V --format --help --version "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
multipass__mount)
opts=" -h -V --help --version <source> <target> "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
multipass__purge)
opts=" -h -V --help --version "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
multipass__recover)
opts=" -h -V --all --help --version <name> "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
multipass__restart)
opts=" -h -V --all --help --version <name> "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
multipass__set)
opts=" -h -V --help --version <keyval> "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
multipass__shell)
opts=" -h -V --help --version <name> "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
multipass__start)
opts=" -h -V --all --help --version <name> "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
multipass__stop)
opts=" -t -c -h -V --all --time --cancel --help --version <name> "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
--time)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
-t)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--cancel)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
-c)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
multipass__suspend)
opts=" -h -V --all --help --version <name> "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
multipass__transfer)
opts=" -h -V --help --version <source> <destination> "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
multipass__umount)
opts=" -h -V --help --version <mount> "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
multipass__version)
opts=" -h -V --help --version "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
esac
}
complete -F _multipass -o bashdefault -o default multipass
#compdef multipass
autoload -U is-at-least
_multipass() {
typeset -A opt_args
typeset -a _arguments_options
local ret=1
if is-at-least 5.2; then
_arguments_options=(-s -S -C)
else
_arguments_options=(-s -C)
fi
local context curcontext="$curcontext" state line
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
":: :_multipass_commands" \
"*::: :->multipass" \
&& ret=0
case $state in
(multipass)
words=($line[1] "${words[@]}")
(( CURRENT += 1 ))
curcontext="${curcontext%:*:*}:multipass-command-$line[1]:"
case $line[1] in
(delete)
_arguments "${_arguments_options[@]}" \
'--all[Delete all instances]' \
'-p[Purge instances immediately]' \
'--purge[Purge instances immediately]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'::name -- Names of instances to delete:' \
&& ret=0
;;
(exec)
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
':name -- Name of instance to execute the command on:' \
':command -- Command to execute on the instance:' \
&& ret=0
;;
(find)
_arguments "${_arguments_options[@]}" \
'--format[Output list in the requested format.Valid formats are: table (default), json, csv and yaml]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'::string -- An optional value to search for in \[<remote\:>\]<string>:' \
&& ret=0
;;
(get)
_arguments "${_arguments_options[@]}" \
'--raw[Output in raw format. For now, this affects only the representation of empty values (i.e. "" instead of "<empty>").]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'::key -- Path to the setting whose configured value should be obtained.:' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
&& ret=0
;;
(info)
_arguments "${_arguments_options[@]}" \
'--all[Display info for all instances]' \
'--format[Output info in the requested format. Valid formats are: table (default), json, csv and yaml]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'::name -- Names of instances to display information about:' \
&& ret=0
;;
(launch)
_arguments "${_arguments_options[@]}" \
'-c+[Number of CPUs to allocate. Minimum: 1, default: 1.]' \
'--cpus=[Number of CPUs to allocate. Minimum: 1, default: 1.]' \
'-m+[Amount of memory to allocate. Positive integers, in bytes, or with K, M, G suffix. Minimum: 128M, default: 1G.]' \
'--mem=[Amount of memory to allocate. Positive integers, in bytes, or with K, M, G suffix. Minimum: 128M, default: 1G.]' \
'-d+[Disk space to allocate. Positive integers, in bytes, or with K, M, G suffix. Minimum: 512M, default: 5G.]' \
'--disk=[Disk space to allocate. Positive integers, in bytes, or with K, M, G suffix. Minimum: 512M, default: 5G.]' \
'-n+[Name for the instance. If it is primary (the configured primary instance name), the user home directory is mounted inside the newly launched instance, in Home.]' \
'--name=[Name for the instance. If it is primary (the configured primary instance name), the user home directory is mounted inside the newly launched instance, in Home.]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'::image -- Optional image to launch. If omitted, then the default Ubuntu LTS will be used.:' \
&& ret=0
;;
(list)
_arguments "${_arguments_options[@]}" \
'--format[Output list in the requested format. Valid formats are: table (default), json, csv and yaml]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
&& ret=0
;;
(mount)
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
':source -- Path of the local directory to mount:' \
':target -- Target mount points, in <name>\[\:<path>\] format, where <name> is an instance name, and optional <path> is the mount point. If omitted, the mount point will be the same as the source absolute path:' \
&& ret=0
;;
(purge)
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
&& ret=0
;;
(recover)
_arguments "${_arguments_options[@]}" \
'--all[Recover all deleted instances]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'::name -- Names of instances to recover:' \
&& ret=0
;;
(restart)
_arguments "${_arguments_options[@]}" \
'--all[Recover all deleted instances]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'::name -- Names of instances to restart. If omitted, and without the --all option, primary will be assumed.:' \
&& ret=0
;;
(set)
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
':keyval -- A key-value pair. The key specifies a path to the setting to configure. The value is its intended value.:' \
&& ret=0
;;
(shell)
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'::name -- Name of the instance to open a shell on. If omitted, primary (the configured primary instance name) will be assumed. If the instance is not running, an attempt is made to start it (see `start` for more info).:' \
&& ret=0
;;
(start)
_arguments "${_arguments_options[@]}" \
'--all[Start all instances]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'::name -- Names of instances to start. If omitted, and without the --all option, primary (the configured primary instance name) will be assumed. If primary does not exist but is included in a successful start command (either implicitly or explicitly), it is launched automatically (see `launch` for more info).:' \
&& ret=0
;;
(stop)
_arguments "${_arguments_options[@]}" \
'-t+[Time from now, in minutes, to delay shutdown of the instance]' \
'--time=[Time from now, in minutes, to delay shutdown of the instance]' \
'-c+[Cancel a pending delayed shutdown]' \
'--cancel=[Cancel a pending delayed shutdown]' \
'--all[Stop all instances]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'::name -- Names of instances to stop. If omitted, and without the --all option, primary will be assumed:' \
&& ret=0
;;
(suspend)
_arguments "${_arguments_options[@]}" \
'--all[Suspend all instances]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'::name -- Names of instances to suspend. If omitted, and without the --all option, primary will be assumed.:' \
&& ret=0
;;
(transfer)
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
':source -- One or more paths to transfer, prefixed with <name\:> for paths inside the instance, or - for stdin:' \
':destination -- The destination path, prefixed with <name\:> for a path inside the instance, or - for stdout:' \
&& ret=0
;;
(umount)
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'::mount -- Mount points, in <name>\[\:<path>\] format, where <name> are instance names, and optional <path> are mount points. If omitted, all mounts will be removed from the named instances.:' \
&& ret=0
;;
(version)
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
&& ret=0
;;
esac
;;
esac
}
(( $+functions[_multipass_commands] )) ||
_multipass_commands() {
local commands; commands=(
"delete:Delete instances" \
"exec:Run a command on an instance" \
"find:Display available images to create instances from" \
"get:Get a configuration setting" \
"help:Display help about a command" \
"info:Display information about instances" \
"launch:Create and start an Ubuntu instance" \
"list:List all available instances" \
"mount:Mount a local directory in the instance" \
"purge:Purge all deleted instances permanently" \
"recover:Recover deleted instances" \
"restart:Restart instances" \
"set:Set a configuration setting" \
"shell:Open a shell on a running instance" \
"start:Start instances" \
"stop:Stop running instances" \
"suspend:Suspend running instances" \
"transfer:Transfer files between the host and instances" \
"umount:Unmount a directory from an instance" \
"version:Show version details" \
)
_describe -t commands 'multipass commands' commands "$@"
}
(( $+functions[_multipass__delete_commands] )) ||
_multipass__delete_commands() {
local commands; commands=(
)
_describe -t commands 'multipass delete commands' commands "$@"
}
(( $+functions[_multipass__exec_commands] )) ||
_multipass__exec_commands() {
local commands; commands=(
)
_describe -t commands 'multipass exec commands' commands "$@"
}
(( $+functions[_multipass__find_commands] )) ||
_multipass__find_commands() {
local commands; commands=(
)
_describe -t commands 'multipass find commands' commands "$@"
}
(( $+functions[_multipass__get_commands] )) ||
_multipass__get_commands() {
local commands; commands=(
)
_describe -t commands 'multipass get commands' commands "$@"
}
(( $+functions[_multipass__help_commands] )) ||
_multipass__help_commands() {
local commands; commands=(
)
_describe -t commands 'multipass help commands' commands "$@"
}
(( $+functions[_multipass__info_commands] )) ||
_multipass__info_commands() {
local commands; commands=(
)
_describe -t commands 'multipass info commands' commands "$@"
}
(( $+functions[_multipass__launch_commands] )) ||
_multipass__launch_commands() {
local commands; commands=(
)
_describe -t commands 'multipass launch commands' commands "$@"
}
(( $+functions[_multipass__list_commands] )) ||
_multipass__list_commands() {
local commands; commands=(
)
_describe -t commands 'multipass list commands' commands "$@"
}
(( $+functions[_multipass__mount_commands] )) ||
_multipass__mount_commands() {
local commands; commands=(
)
_describe -t commands 'multipass mount commands' commands "$@"
}
(( $+functions[_multipass__purge_commands] )) ||
_multipass__purge_commands() {
local commands; commands=(
)
_describe -t commands 'multipass purge commands' commands "$@"
}
(( $+functions[_multipass__recover_commands] )) ||
_multipass__recover_commands() {
local commands; commands=(
)
_describe -t commands 'multipass recover commands' commands "$@"
}
(( $+functions[_multipass__restart_commands] )) ||
_multipass__restart_commands() {
local commands; commands=(
)
_describe -t commands 'multipass restart commands' commands "$@"
}
(( $+functions[_multipass__set_commands] )) ||
_multipass__set_commands() {
local commands; commands=(
)
_describe -t commands 'multipass set commands' commands "$@"
}
(( $+functions[_multipass__shell_commands] )) ||
_multipass__shell_commands() {
local commands; commands=(
)
_describe -t commands 'multipass shell commands' commands "$@"
}
(( $+functions[_multipass__start_commands] )) ||
_multipass__start_commands() {
local commands; commands=(
)
_describe -t commands 'multipass start commands' commands "$@"
}
(( $+functions[_multipass__stop_commands] )) ||
_multipass__stop_commands() {
local commands; commands=(
)
_describe -t commands 'multipass stop commands' commands "$@"
}
(( $+functions[_multipass__suspend_commands] )) ||
_multipass__suspend_commands() {
local commands; commands=(
)
_describe -t commands 'multipass suspend commands' commands "$@"
}
(( $+functions[_multipass__transfer_commands] )) ||
_multipass__transfer_commands() {
local commands; commands=(
)
_describe -t commands 'multipass transfer commands' commands "$@"
}
(( $+functions[_multipass__umount_commands] )) ||
_multipass__umount_commands() {
local commands; commands=(
)
_describe -t commands 'multipass umount commands' commands "$@"
}
(( $+functions[_multipass__version_commands] )) ||
_multipass__version_commands() {
local commands; commands=(
)
_describe -t commands 'multipass version commands' commands "$@"
}
_multipass "$@"
@linux-china
Copy link
Author

linux-china commented Nov 13, 2020

shell completion for bash and zsh supported by https://github.com/clap-rs/clap
How to use?

  • bash: source multipass_completion.sh
  • fish: source multipass_completion.fish
  • zsh: cp multipass_completion.zsh /usr/local/share/zsh/site-functions/_multipass
  • oh-my-zsh
$ mkdir ~/.oh-my-zsh/custom/plugins/multipass
$ cp multipass_completion.zsh ~/.oh-my-zsh/custom/plugins/multipass/_multipass

enable multipass plugin in .zshrc

screenshot like this:

Snip20201113_117

@flying-sausages
Copy link

Does it make sense to do #!/usr/bin/env bash ? Would this not get sourced into the wrong shell?

@linux-china
Copy link
Author

Does it make sense to do #!/usr/bin/env bash ? Would this not get sourced into the wrong shell?

rewrite with clap-rs and it works well now.

@flying-sausages
Copy link

flying-sausages commented Nov 14, 2020

I think it would be nice to move this to its own Repo / make a PR against multipass :) Also, adding the method for how these got generated would probably be quite useful to make this maintainable

@flying-sausages
Copy link

also, any chance to get the Name completions in the zsh script?
You can get a list of these through multipass list --format table | sed "1 d" | cut -d' ' -f 1 or through csv by using multipass list --format csv | sed "1 d" | cut -d, -f 1 or otherwise by using the json or yaml outputs as well.

@linux-china
Copy link
Author

Please visit https://github.com/linux-china/cli-completion , and use cli-completion to generate completion by multpass.yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment