chiark / gitweb /
zsh-completion: Move machine listing to autoload
authorWilliam Giokas <1007380@gmail.com>
Thu, 7 Nov 2013 22:00:51 +0000 (16:00 -0600)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 10 Nov 2013 00:02:53 +0000 (19:02 -0500)
Instead of having two different listings of machines, use an autoloaded
function that can be used by other shell completions in the future. It
will also allow editing a single file to change the way machinectl and
systemd-run completion for machines.

shell-completion/zsh/_machinectl
shell-completion/zsh/_sd_machines [new file with mode: 0644]
shell-completion/zsh/_systemd-run

index 2e5e05cfcc25f3be693da0e5556c8ae3b9335c31..026d74fca406933e0947ff8dc9ef1303e5419a9b 100644 (file)
       case $cmd in
         list) msg="no options" ;;
         *)
-          _machines=( "${(foa)$(machinectl list | awk '{print $1}')}" )
-          if [[ -n "$_machines" ]]; then
-            _describe 'machines' _machines
-          else
-            _message 'no machines'
-          fi
+          _sd_machines
       esac
     else
       _message "no more options"
diff --git a/shell-completion/zsh/_sd_machines b/shell-completion/zsh/_sd_machines
new file mode 100644 (file)
index 0000000..1d64d13
--- /dev/null
@@ -0,0 +1,13 @@
+#autoload
+__get_machines () {
+        machinectl --full --no-pager list | {while read -r a b; do echo $a; done;};
+}
+
+local -a _machines
+_machines=("${(fo)$(__get_machines)}")
+typeset -U _machines
+if [[ -n "$_machines" ]]; then
+        _describe 'machines' _machines
+else
+        _message 'no machines'
+fi
index 4bfbd196ca6c9e7feb29eb93807e913457a81e24..9bb770072e3d4848c2c73f742338d082d858f43c 100644 (file)
@@ -18,27 +18,12 @@ __slices () {
         _describe 'slices' _slices
 }
 
-__get_machines () {
-        machinectl --full --no-pager list | {while read -r a b; do echo $a; done;};
-}
-
-__machines () {
-        local -a _machines
-        _machines=("${(fo)$(__get_machines)}")
-        typeset -U _machines
-        if [[ -n "$_machines" ]]; then
-                _describe 'machines' _machines
-        else
-                _message 'no machines'
-        fi
-}
-
 _arguments \
         {-h,--help}'[Show help message]' \
         '--version[Show package version]' \
         '--user[Run as user unit]' \
         {-H+,--host=}'[Operate on remote host]:[user@]host:_sd_hosts_or_user_at_host' \
-        {-M+,--machine=}'[Operate on local container]:machines:__machines' \
+        {-M+,--machine=}'[Operate on local container]:machines:_sd_machines' \
         '--scope[Run this as scope rather than service]' \
         '--unit=[Run under the specified unit name]:unit name' \
         '--description=[Description for unit]:description' \