teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone
Blob Blame History Raw
From 49323e421a0fad064e3258ca26ae8c80a3386666 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Mon, 14 Jul 2014 19:24:46 -0400
Subject: [PATCH] shell-completion: restore completion for -p

It was broken since systemd was moved out of /bin.

For zsh it was never there.

(cherry picked from commit c0a67aef31bb9716617ffe150ca8be19c5df203e)
---
 Makefile.am                                        | 19 +++++++++++++++++--
 shell-completion/bash/.gitignore                   |  1 +
 shell-completion/bash/{systemctl => systemctl.in}  |  4 ++--
 shell-completion/zsh/.gitignore                    |  1 +
 shell-completion/zsh/{_systemctl => _systemctl.in} | 15 ++++++++++++++-
 5 files changed, 35 insertions(+), 5 deletions(-)
 create mode 100644 shell-completion/bash/.gitignore
 rename shell-completion/bash/{systemctl => systemctl.in} (98%)
 create mode 100644 shell-completion/zsh/.gitignore
 rename shell-completion/zsh/{_systemctl => _systemctl.in} (95%)

diff --git a/Makefile.am b/Makefile.am
index 025461b497..9847ff50bc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -383,7 +383,6 @@ systemgenerator_PROGRAMS = \
 dist_bashcompletion_DATA = \
 	shell-completion/bash/busctl \
 	shell-completion/bash/journalctl \
-	shell-completion/bash/systemctl \
 	shell-completion/bash/systemd-analyze \
 	shell-completion/bash/systemd-cat \
 	shell-completion/bash/systemd-cgls \
@@ -395,8 +394,10 @@ dist_bashcompletion_DATA = \
 	shell-completion/bash/udevadm \
 	shell-completion/bash/kernel-install
 
+nodist_bashcompletion_DATA = \
+	shell-completion/bash/systemctl
+
 dist_zshcompletion_DATA = \
-	shell-completion/zsh/_systemctl \
 	shell-completion/zsh/_journalctl \
 	shell-completion/zsh/_udevadm \
 	shell-completion/zsh/_kernel-install \
@@ -407,6 +408,17 @@ dist_zshcompletion_DATA = \
 	shell-completion/zsh/_systemd-delta \
 	shell-completion/zsh/_systemd
 
+nodist_zshcompletion_DATA = \
+	shell-completion/zsh/_systemctl
+
+EXTRA_DIST += \
+	shell-completion/bash/systemctl.in \
+	shell-completion/zsh/_systemctl.in
+
+CLEANFILES += \
+	$(nodist_bashcompletion_DATA) \
+	$(nodist_zshcompletion_DATA)
+
 dist_sysctl_DATA = \
 	sysctl.d/50-default.conf
 
@@ -5196,6 +5208,9 @@ src/core/macros.%: src/core/macros.%.in
 src/%.policy.in: src/%.policy.in.in
 	$(SED_PROCESS)
 
+shell-completion/%: shell-completion/%.in
+	$(SED_PROCESS)
+
 %.rules: %.rules.in
 	$(SED_PROCESS)
 
diff --git a/shell-completion/bash/.gitignore b/shell-completion/bash/.gitignore
new file mode 100644
index 0000000000..016e09d1e7
--- /dev/null
+++ b/shell-completion/bash/.gitignore
@@ -0,0 +1 @@
+/systemctl
diff --git a/shell-completion/bash/systemctl b/shell-completion/bash/systemctl.in
similarity index 98%
rename from shell-completion/bash/systemctl
rename to shell-completion/bash/systemctl.in
index e1c842006e..4beec4e13f 100644
--- a/shell-completion/bash/systemctl
+++ b/shell-completion/bash/systemctl.in
@@ -24,8 +24,8 @@ __systemctl() {
 
 __systemd_properties() {
         local mode=$1
-        { __systemctl -a $mode show;
-         systemd --dump-configuration-items; } |
+        { __systemctl $mode show --all;
+         @rootlibexecdir@/systemd --dump-configuration-items; } |
         while IFS='=' read -r key value; do
             [[ $value ]] && echo "$key"
         done
diff --git a/shell-completion/zsh/.gitignore b/shell-completion/zsh/.gitignore
new file mode 100644
index 0000000000..75f13ad6d1
--- /dev/null
+++ b/shell-completion/zsh/.gitignore
@@ -0,0 +1 @@
+/_systemctl
diff --git a/shell-completion/zsh/_systemctl b/shell-completion/zsh/_systemctl.in
similarity index 95%
rename from shell-completion/zsh/_systemctl
rename to shell-completion/zsh/_systemctl.in
index b6cf664587..d9b8d1c0e3 100644
--- a/shell-completion/zsh/_systemctl
+++ b/shell-completion/zsh/_systemctl.in
@@ -301,12 +301,25 @@ _unit_types() {
     _values -s , "${_types[@]}"
 }
 
+_unit_properties() {
+  if ( [[ ${+_sys_all_properties} -eq 0 ]] || _cache_invalid SYS_ALL_PROPERTIES ) &&
+    ! _retrieve_cache SYS_ALL_PROPERTIES;
+  then
+    _sys_all_properties=( $( {__systemctl show --all;
+       @rootlibexecdir@/systemd --dump-configuration-items; } | {
+       while IFS='=' read -r a b; do [ -n "$b" ] && echo "$a"; done
+    }) )
+    _store_cache SYS_ALL_PROPRTIES _sys_all_properties
+  fi
+  _values -s , "${_sys_all_properties[@]}"
+}
+
 _arguments -s \
     {-h,--help}'[Show help]' \
     '--version[Show package version]' \
     {-t+,--type=}'[List only units of a particular type]:unit type:_unit_types' \
     '--state=[Display units in the specifyied state]:unit state:_unit_states' \
-    \*{-p+,--property=}'[Show only properties by specific name]:unit property' \
+    {-p+,--property=}'[Show only properties by specific name]:unit property:_unit_properties' \
     {-a,--all}'[Show all units/properties, including dead/empty ones]' \
     '--reverse[Show reverse dependencies]' \
     '--after[Show units ordered after]' \