1
0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-25 09:41:20 +08:00

feat(multipass): add plugin for multipass (#10140)

Co-authored-by: C. Yavuzsen <cyavuzsen@comscore.com>
This commit is contained in:
Civan Yavuzşen 2022-02-01 23:48:14 +01:00 committed by GitHub
parent 0be7c897f8
commit 4ee0cf3cb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 102 additions and 0 deletions

View File

@ -0,0 +1,22 @@
# multipass
This plugin provides completion for [multipass](https://multipass.run), as well as aliases
for multipass commands.
To use it, add `multipass` to the plugins array in your zshrc file:
```zsh
plugins=(... multipass)
```
## Aliases
| Alias | Command |
| ------ | ------------------------------------------------------------------- |
| `mp` | `multipass` |
| `mpl` | `multipass list` |
| `mpla` | `multipass launch` |
| `mpln` | `multipass launch --network en0 --network name=bridge0,mode=manual` |
| `mps` | `multipass shell` |
| `mpsp` | `multipass stop` |
| `mpst` | `multipass start` |

View File

@ -0,0 +1,73 @@
#compdef multipass
_multipass_get_command_list () {
# Sample output:
# $ multipass --help
# ...
# Options:
# -h, --help Display this help
# -v, --verbose Increase logging verbosity. Repeat the 'v' in the short option
# for more detail. Maximum verbosity is obtained with 4 (or more)
# v's, i.e. -vvvv.
# ...
# Available commands:
# alias Create an alias
# aliases List available aliases
# ...
#
$_comp_command1 --help | sed '1,/Available commands/d' | awk '/^[ \t]*[a-z]+/ { print $1 }'
}
_multipass_get_args_list () {
# Sample output:
# $ multpass help stop
# ...
# Options:
# -h, --help Display this help
# -v, --verbose Increase logging verbosity. Repeat the 'v' in the short
# option for more detail. Maximum verbosity is obtained with
# 4 (or more) v's, i.e. -vvvv.
# --all Stop all instances
# -t, --time <time> Time from now, in minutes, to delay shutdown of the
# instance
# -c, --cancel Cancel a pending delayed shutdown
#
# Arguments:
# name Names of instances to stop. If omitted, and without the
# --all option, 'primary' will be assumed.
#
local arg_name=$($_comp_command1 help ${words[2]} | sed '1,/Arguments/d' | awk '/^[ \t]*[a-z]+/ { print $1; exit }')
case $arg_name in
name)
# Sample output:
# $ multipass list
# Name State IPv4 Image
# workable-poacher Running 10.2.0.28 Ubuntu openHAB Home Appliance
#
$_comp_command1 list | sed '1d' | awk '/^[ \t]*[^ ]+/ { print $1 }'
;;
command)
_multipass_get_command_list
;;
esac
}
_multipass () {
typeset -A opt_args
_arguments \
'1: :->command'\
'*: :->args'
case $state in
command)
compadd $(_multipass_get_command_list)
;;
*)
compadd $(_multipass_get_args_list)
;;
esac
}
_multipass "$@"

View File

@ -0,0 +1,7 @@
alias mp="multipass"
alias mpl="multipass list"
alias mpla="multipass launch"
alias mpln="multipass launch --network en0 --network name=bridge0,mode=manual"
alias mps="multipass shell"
alias mpsp="multipass stop"
alias mpst="multipass start"