[systemd-devel] [PATCH] zsh_completion: Move helper function to autoload

William Giokas 1007380 at gmail.com
Mon Aug 12 10:41:18 PDT 2013


_hosts_or_user_at_host was used by 6 different completions, and
previously was in all 6 of those files. I moved it out to its own file,
_sd_hosts_or_user_at_host. This will be autoloaded for use in other
completion functions. It also allows external completions to use this
function by simply calling _sd_hosts_or_user_at_host as in the systemd
completions.
---

I noticed this when looking at the _machinectl completions and seeing no
function of that name in the file. I think that this will make things
easier in the future.

The '_sd_' is just to prevent name conflicts if some other program
provides _hosts_or_user_at_host.

 Makefile.am                                    | 1 +
 shell-completion/zsh/_hostnamectl              | 8 +-------
 shell-completion/zsh/_localectl                | 8 +-------
 shell-completion/zsh/_loginctl                 | 8 +-------
 shell-completion/zsh/_machinectl               | 2 +-
 shell-completion/zsh/_sd_hosts_or_user_at_host | 5 +++++
 shell-completion/zsh/_systemctl                | 8 +-------
 shell-completion/zsh/_timedatectl              | 8 +-------
 8 files changed, 12 insertions(+), 36 deletions(-)
 create mode 100644 shell-completion/zsh/_sd_hosts_or_user_at_host

diff --git a/Makefile.am b/Makefile.am
index b8b8d06..0590e4d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -350,6 +350,7 @@ dist_zshcompletion_DATA = \
 	shell-completion/zsh/_kernel-install \
 	shell-completion/zsh/_systemd-nspawn \
 	shell-completion/zsh/_systemd-analyze \
+	shell-completion/zsh/_sd_hosts_or_user_at_host \
 	shell-completion/zsh/_systemd
 
 dist_sysctl_DATA = \
diff --git a/shell-completion/zsh/_hostnamectl b/shell-completion/zsh/_hostnamectl
index bc4441d..9d01495 100644
--- a/shell-completion/zsh/_hostnamectl
+++ b/shell-completion/zsh/_hostnamectl
@@ -1,11 +1,5 @@
 #compdef hostnamectl
 
-_hosts_or_user_at_host() {
-  _alternative \
-    'users-hosts:: _user_at_host' \
-    'hosts:: _hosts'
-}
-
 _hostnamectl_command() {
     local -a _hostnamectl_cmds
     _hostnamectl_cmds=(
@@ -34,5 +28,5 @@ _arguments -s \
     '--static[Only set static hostname]' \
     '--pretty[Only set pretty hostname]' \
     '--no-ask-password[Do not prompt for password]' \
-    {-H,--host=}'[Operate on remote host]:userathost:_hosts_or_user_at_host' \
+    {-H,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \
     '*::hostnamectl commands:_hostnamectl_command'
diff --git a/shell-completion/zsh/_localectl b/shell-completion/zsh/_localectl
index 0beed4f..321e418 100644
--- a/shell-completion/zsh/_localectl
+++ b/shell-completion/zsh/_localectl
@@ -73,17 +73,11 @@ _localectl_command() {
     fi
 }
 
-_hosts_or_user_at_host() {
-  _alternative \
-    'users-hosts:: _user_at_host' \
-    'hosts:: _hosts'
-}
-
 _arguments \
     {-h,--help}'[Show this help]' \
     '--version[Show package version]' \
     "--no-convert[Don't convert keyboard mappings]" \
     '--no-pager[Do not pipe output into a pager]' \
     '--no-ask-password[Do not prompt for password]' \
-    {-H,--host=}'[Operate on remote host]:userathost:_hosts_or_user_at_host' \
+    {-H,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \
     '*::localectl commands:_localectl_command'
diff --git a/shell-completion/zsh/_loginctl b/shell-completion/zsh/_loginctl
index d121a25..6d88685 100644
--- a/shell-completion/zsh/_loginctl
+++ b/shell-completion/zsh/_loginctl
@@ -1,11 +1,5 @@
 #compdef loginctl
 
-_hosts_or_user_at_host() {
-  _alternative \
-    'users-hosts:: _user_at_host' \
-    'hosts:: _hosts'
-}
-
 _loginctl_all_sessions(){_sys_all_sessions=($(loginctl list-sessions | { while read a b; do echo " $a"; done; }) )}
 _loginctl_all_users()   {_sys_all_users=(   $(loginctl list-users    | { while read a b; do echo " $a"; done; }) )}
 _loginctl_all_seats()   {_sys_all_seats=(   $(loginctl list-seats    | { while read a b; do echo " $a"; done; }) )}
@@ -106,7 +100,7 @@ _arguments -s \
     '--kill-who=[Who to send signal to]:killwho:(main control all)' \
     {-s,--signal=}'[Which signal to send]:signal:_signals' \
     '--no-ask-password[Do not ask for system passwords]' \
-    {-H,--host=}'[Show information for remote host]:userathost:_hosts_or_user_at_host' \
+    {-H,--host=}'[Show information for remote host]:userathost:_sd_hosts_or_user_at_host' \
     {-P,--privileged}'[Acquire privileges before execution]' \
     '--no-pager[Do not pipe output into a pager]' \
     '*::loginctl command:_loginctl_command'
diff --git a/shell-completion/zsh/_machinectl b/shell-completion/zsh/_machinectl
index 89196a5..aa568e5 100644
--- a/shell-completion/zsh/_machinectl
+++ b/shell-completion/zsh/_machinectl
@@ -42,6 +42,6 @@ _arguments \
   '--no-ask-password[Do not ask for system passwords]' \
   '--kill-who=[Who to send signal to]:killwho:(leader all)' \
   {-s,--signal=}'[Which signal to send]:signal:_signals' \
-  {-H,--host=}'[Show information for remote host]:userathost:_hosts_or_user_at_host' \
+  {-H,--host=}'[Show information for remote host]:userathost:_sd_hosts_or_user_at_host' \
   {-P,--privileged}'[Acquire privileges before execution]' \
   '*::machinectl command:_machinectl_command'
diff --git a/shell-completion/zsh/_sd_hosts_or_user_at_host b/shell-completion/zsh/_sd_hosts_or_user_at_host
new file mode 100644
index 0000000..282f732
--- /dev/null
+++ b/shell-completion/zsh/_sd_hosts_or_user_at_host
@@ -0,0 +1,5 @@
+#autoload
+
+_alternative \
+  'users-hosts:: _user_at_host' \
+  'hosts:: _hosts'
diff --git a/shell-completion/zsh/_systemctl b/shell-completion/zsh/_systemctl
index 70d6f33..f8b191f 100644
--- a/shell-completion/zsh/_systemctl
+++ b/shell-completion/zsh/_systemctl
@@ -288,12 +288,6 @@ _systemctl_caching_policy()
   return 1
 }
 
-_hosts_or_user_at_host() {
-  _alternative \
-    'users-hosts:: _user_at_host' \
-    'hosts:: _hosts'
-}
-
 _outputmodes() {
     local -a _output_opts
     _output_opts=(short short-monotonic verbose export json json-pretty json-see cat)
@@ -332,7 +326,7 @@ _arguments -s \
     {-f,--force}'[When enabling unit files, override existing symlinks. When shutting down, execute action immediately]' \
     '--root=[Enable unit files in the specified root directory]:directory:_directories' \
     '--runtime[Enable unit files only temporarily until next reboot]' \
-    {-H,--host=}'[Show information for remote host]:userathost:_hosts_or_user_at_host' \
+    {-H,--host=}'[Show information for remote host]:userathost:_sd_hosts_or_user_at_host' \
     {-P,--privileged}'[Acquire privileges before execution]' \
     {-n,--lines=}'[Journal entries to show]:number of entries' \
     {-o,--output=}'[Change journal output mode]:modes:_outputmodes' \
diff --git a/shell-completion/zsh/_timedatectl b/shell-completion/zsh/_timedatectl
index 091b6f1..9e24b86 100644
--- a/shell-completion/zsh/_timedatectl
+++ b/shell-completion/zsh/_timedatectl
@@ -55,17 +55,11 @@ _timedatectl_command(){
     fi
 }
 
-_hosts_or_user_at_host() {
-  _alternative \
-    'users-hosts:: _user_at_host' \
-    'hosts:: _hosts'
-}
-
 _arguments -s \
     {-h,--help}'[Show this help]' \
     '--version[Show package version]' \
     '--adjust-system-clock[Adjust system clock when changing local RTC mode]' \
     '--no-pager[Do not pipe output into a pager]' \
     '--no-ask-password[Do not prompt for password]' \
-    {-H,--host=}'[Operate on remote host]:userathost:_hosts_or_user_at_host' \
+    {-H,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \
     '*::timedatectl commands:_timedatectl_command'
-- 
1.8.4.rc2.458.gc9b7461



More information about the systemd-devel mailing list