f742baf73ccb70c94952717b5152f97a176eef3a

Author
Renato dos Santos <shazaum@gmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

Add plugin for LXD autocomplete (#7457)

Diff

 1diff --git a/plugins/lxd/README.md b/plugins/lxd/README.md
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..cea45e31c79b72c2adc2777dd0925554f31106a8
 4--- /dev/null
 5+++ b/plugins/lxd/README.md
 6@@ -0,0 +1,9 @@
 7+# lxd
 8+
 9+This plugin provides completion for [lxd](https://linuxcontainers.org/lxd/), as well as aliases
10+for frequent lxc commands.
11+
12+To use it add `lxd` to the plugins array in your zshrc file.
13+
14+```zsh
15+plugins=(... lxd)
16diff --git a/plugins/lxd/lxd.plugin.zsh b/plugins/lxd/lxd.plugin.zsh
17new file mode 100644
18index 0000000000000000000000000000000000000000..a6a07425281183bf21037ed9a3a42ca283badbdb
19--- /dev/null
20+++ b/plugins/lxd/lxd.plugin.zsh
21@@ -0,0 +1,26 @@
22+_lxc_get_command_list () {
23+    $_comp_command1 | sed "1,/Available Commands/d" | awk '/^[ \t]*[a-z]+/ { print $1 }'
24+}
25+
26+_lxc_get_subcommand_list () {
27+    $_comp_command1 ${words[2]} | sed "1,/Available Commands/d" | awk '/^[ \t]*[a-z]+/ { print $1 }'
28+}
29+
30+_lxc () {
31+  local curcontext="$curcontext" state line
32+  typeset -A opt_args
33+  _arguments \
34+    '1: :->command'\
35+    '*: :->args'
36+
37+  case $state in
38+    command)
39+      compadd $(_lxc_get_command_list)
40+      ;;
41+    *)
42+        compadd $(_lxc_get_subcommand_list)
43+      ;;
44+  esac
45+}
46+
47+compdef _lxc lxc