4ee0cf3cb4c64568430f9af5b1edca2602ab5807

Author
Civan Yavuzşen <civanyavuzsen@gmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

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

Co-authored-by: C. Yavuzsen <cyavuzsen@comscore.com>

Diff

  1diff --git a/plugins/multipass/README.md b/plugins/multipass/README.md
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..f6b2d76f4e2148b2dcf34464d15dca7cf38c996a
  4--- /dev/null
  5+++ b/plugins/multipass/README.md
  6@@ -0,0 +1,22 @@
  7+# multipass
  8+
  9+This plugin provides completion for [multipass](https://multipass.run), as well as aliases
 10+for multipass commands.
 11+
 12+To use it, add `multipass` to the plugins array in your zshrc file:
 13+
 14+```zsh
 15+plugins=(... multipass)
 16+```
 17+
 18+## Aliases
 19+
 20+| Alias  | Command                                                             |
 21+| ------ | ------------------------------------------------------------------- |
 22+| `mp`   | `multipass`                                                         |
 23+| `mpl`  | `multipass list`                                                    |
 24+| `mpla` | `multipass launch`                                                  |
 25+| `mpln` | `multipass launch --network en0 --network name=bridge0,mode=manual` |
 26+| `mps`  | `multipass shell`                                                   |
 27+| `mpsp` | `multipass stop`                                                    |
 28+| `mpst` | `multipass start`                                                   |
 29diff --git a/plugins/multipass/_multipass b/plugins/multipass/_multipass
 30new file mode 100644
 31index 0000000000000000000000000000000000000000..c742df65053f1c723f585bf5aad3cbbba509c620
 32--- /dev/null
 33+++ b/plugins/multipass/_multipass
 34@@ -0,0 +1,73 @@
 35+#compdef multipass
 36+
 37+_multipass_get_command_list () {
 38+  # Sample output:
 39+  # $ multipass --help
 40+  # ...
 41+  # Options:
 42+  #   -h, --help     Display this help
 43+  #   -v, --verbose  Increase logging verbosity. Repeat the 'v' in the short option
 44+  #                  for more detail. Maximum verbosity is obtained with 4 (or more)
 45+  #                  v's, i.e. -vvvv.
 46+  # ...
 47+  # Available commands:
 48+  #   alias     Create an alias
 49+  #   aliases   List available aliases
 50+  #   ...
 51+  #
 52+  $_comp_command1 --help | sed '1,/Available commands/d' | awk '/^[ \t]*[a-z]+/ { print $1 }'
 53+}
 54+
 55+_multipass_get_args_list () {
 56+  # Sample output:
 57+  # $ multpass help stop
 58+  # ...
 59+  # Options:
 60+  # -h, --help         Display this help
 61+  # -v, --verbose      Increase logging verbosity. Repeat the 'v' in the short
 62+  #                     option for more detail. Maximum verbosity is obtained with
 63+  #                     4 (or more) v's, i.e. -vvvv.
 64+  # --all              Stop all instances
 65+  # -t, --time <time>  Time from now, in minutes, to delay shutdown of the
 66+  #                     instance
 67+  # -c, --cancel       Cancel a pending delayed shutdown
 68+  #
 69+  # Arguments:
 70+  # name               Names of instances to stop. If omitted, and without the
 71+  #                     --all option, 'primary' will be assumed.
 72+  #
 73+  local arg_name=$($_comp_command1 help ${words[2]} | sed '1,/Arguments/d' | awk '/^[ \t]*[a-z]+/ { print $1; exit }')
 74+
 75+  case $arg_name in
 76+    name)
 77+      # Sample output:
 78+      # $ multipass list
 79+      # Name                    State             IPv4             Image
 80+      # workable-poacher        Running           10.2.0.28        Ubuntu openHAB Home Appliance
 81+      #
 82+      $_comp_command1 list | sed '1d' | awk '/^[ \t]*[^ ]+/ { print $1 }'
 83+    ;;
 84+    command)
 85+      _multipass_get_command_list
 86+    ;;
 87+  esac
 88+}
 89+
 90+_multipass () {
 91+  typeset -A opt_args
 92+
 93+  _arguments \
 94+    '1: :->command'\
 95+    '*: :->args'
 96+
 97+  case $state in
 98+    command)
 99+      compadd $(_multipass_get_command_list)
100+    ;;
101+    *)
102+      compadd $(_multipass_get_args_list)
103+    ;;
104+  esac
105+}
106+
107+_multipass "$@"
108diff --git a/plugins/multipass/multipass.plugin.zsh b/plugins/multipass/multipass.plugin.zsh
109new file mode 100644
110index 0000000000000000000000000000000000000000..95025b2adce1c62c71f4c49908cba0be958f84a1
111--- /dev/null
112+++ b/plugins/multipass/multipass.plugin.zsh
113@@ -0,0 +1,7 @@
114+alias mp="multipass"
115+alias mpl="multipass list"
116+alias mpla="multipass launch"
117+alias mpln="multipass launch --network en0 --network name=bridge0,mode=manual"
118+alias mps="multipass shell"
119+alias mpsp="multipass stop"
120+alias mpst="multipass start"