43ff24c
From 49323e421a0fad064e3258ca26ae8c80a3386666 Mon Sep 17 00:00:00 2001
43ff24c
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
43ff24c
Date: Mon, 14 Jul 2014 19:24:46 -0400
43ff24c
Subject: [PATCH] shell-completion: restore completion for -p
43ff24c
43ff24c
It was broken since systemd was moved out of /bin.
43ff24c
43ff24c
For zsh it was never there.
43ff24c
43ff24c
(cherry picked from commit c0a67aef31bb9716617ffe150ca8be19c5df203e)
43ff24c
---
43ff24c
 Makefile.am                                        | 19 +++++++++++++++++--
43ff24c
 shell-completion/bash/.gitignore                   |  1 +
43ff24c
 shell-completion/bash/{systemctl => systemctl.in}  |  4 ++--
43ff24c
 shell-completion/zsh/.gitignore                    |  1 +
43ff24c
 shell-completion/zsh/{_systemctl => _systemctl.in} | 15 ++++++++++++++-
43ff24c
 5 files changed, 35 insertions(+), 5 deletions(-)
43ff24c
 create mode 100644 shell-completion/bash/.gitignore
43ff24c
 rename shell-completion/bash/{systemctl => systemctl.in} (98%)
43ff24c
 create mode 100644 shell-completion/zsh/.gitignore
43ff24c
 rename shell-completion/zsh/{_systemctl => _systemctl.in} (95%)
43ff24c
43ff24c
diff --git a/Makefile.am b/Makefile.am
43ff24c
index 025461b497..9847ff50bc 100644
43ff24c
--- a/Makefile.am
43ff24c
+++ b/Makefile.am
43ff24c
@@ -383,7 +383,6 @@ systemgenerator_PROGRAMS = \
43ff24c
 dist_bashcompletion_DATA = \
43ff24c
 	shell-completion/bash/busctl \
43ff24c
 	shell-completion/bash/journalctl \
43ff24c
-	shell-completion/bash/systemctl \
43ff24c
 	shell-completion/bash/systemd-analyze \
43ff24c
 	shell-completion/bash/systemd-cat \
43ff24c
 	shell-completion/bash/systemd-cgls \
43ff24c
@@ -395,8 +394,10 @@ dist_bashcompletion_DATA = \
43ff24c
 	shell-completion/bash/udevadm \
43ff24c
 	shell-completion/bash/kernel-install
43ff24c
 
43ff24c
+nodist_bashcompletion_DATA = \
43ff24c
+	shell-completion/bash/systemctl
43ff24c
+
43ff24c
 dist_zshcompletion_DATA = \
43ff24c
-	shell-completion/zsh/_systemctl \
43ff24c
 	shell-completion/zsh/_journalctl \
43ff24c
 	shell-completion/zsh/_udevadm \
43ff24c
 	shell-completion/zsh/_kernel-install \
43ff24c
@@ -407,6 +408,17 @@ dist_zshcompletion_DATA = \
43ff24c
 	shell-completion/zsh/_systemd-delta \
43ff24c
 	shell-completion/zsh/_systemd
43ff24c
 
43ff24c
+nodist_zshcompletion_DATA = \
43ff24c
+	shell-completion/zsh/_systemctl
43ff24c
+
43ff24c
+EXTRA_DIST += \
43ff24c
+	shell-completion/bash/systemctl.in \
43ff24c
+	shell-completion/zsh/_systemctl.in
43ff24c
+
43ff24c
+CLEANFILES += \
43ff24c
+	$(nodist_bashcompletion_DATA) \
43ff24c
+	$(nodist_zshcompletion_DATA)
43ff24c
+
43ff24c
 dist_sysctl_DATA = \
43ff24c
 	sysctl.d/50-default.conf
43ff24c
 
43ff24c
@@ -5196,6 +5208,9 @@ src/core/macros.%: src/core/macros.%.in
43ff24c
 src/%.policy.in: src/%.policy.in.in
43ff24c
 	$(SED_PROCESS)
43ff24c
 
43ff24c
+shell-completion/%: shell-completion/%.in
43ff24c
+	$(SED_PROCESS)
43ff24c
+
43ff24c
 %.rules: %.rules.in
43ff24c
 	$(SED_PROCESS)
43ff24c
 
43ff24c
diff --git a/shell-completion/bash/.gitignore b/shell-completion/bash/.gitignore
43ff24c
new file mode 100644
43ff24c
index 0000000000..016e09d1e7
43ff24c
--- /dev/null
43ff24c
+++ b/shell-completion/bash/.gitignore
43ff24c
@@ -0,0 +1 @@
43ff24c
+/systemctl
43ff24c
diff --git a/shell-completion/bash/systemctl b/shell-completion/bash/systemctl.in
43ff24c
similarity index 98%
43ff24c
rename from shell-completion/bash/systemctl
43ff24c
rename to shell-completion/bash/systemctl.in
43ff24c
index e1c842006e..4beec4e13f 100644
43ff24c
--- a/shell-completion/bash/systemctl
43ff24c
+++ b/shell-completion/bash/systemctl.in
43ff24c
@@ -24,8 +24,8 @@ __systemctl() {
43ff24c
 
43ff24c
 __systemd_properties() {
43ff24c
         local mode=$1
43ff24c
-        { __systemctl -a $mode show;
43ff24c
-         systemd --dump-configuration-items; } |
43ff24c
+        { __systemctl $mode show --all;
43ff24c
+         @rootlibexecdir@/systemd --dump-configuration-items; } |
43ff24c
         while IFS='=' read -r key value; do
43ff24c
             [[ $value ]] && echo "$key"
43ff24c
         done
43ff24c
diff --git a/shell-completion/zsh/.gitignore b/shell-completion/zsh/.gitignore
43ff24c
new file mode 100644
43ff24c
index 0000000000..75f13ad6d1
43ff24c
--- /dev/null
43ff24c
+++ b/shell-completion/zsh/.gitignore
43ff24c
@@ -0,0 +1 @@
43ff24c
+/_systemctl
43ff24c
diff --git a/shell-completion/zsh/_systemctl b/shell-completion/zsh/_systemctl.in
43ff24c
similarity index 95%
43ff24c
rename from shell-completion/zsh/_systemctl
43ff24c
rename to shell-completion/zsh/_systemctl.in
43ff24c
index b6cf664587..d9b8d1c0e3 100644
43ff24c
--- a/shell-completion/zsh/_systemctl
43ff24c
+++ b/shell-completion/zsh/_systemctl.in
43ff24c
@@ -301,12 +301,25 @@ _unit_types() {
43ff24c
     _values -s , "${_types[@]}"
43ff24c
 }
43ff24c
 
43ff24c
+_unit_properties() {
43ff24c
+  if ( [[ ${+_sys_all_properties} -eq 0 ]] || _cache_invalid SYS_ALL_PROPERTIES ) &&
43ff24c
+    ! _retrieve_cache SYS_ALL_PROPERTIES;
43ff24c
+  then
43ff24c
+    _sys_all_properties=( $( {__systemctl show --all;
43ff24c
+       @rootlibexecdir@/systemd --dump-configuration-items; } | {
43ff24c
+       while IFS='=' read -r a b; do [ -n "$b" ] && echo "$a"; done
43ff24c
+    }) )
43ff24c
+    _store_cache SYS_ALL_PROPRTIES _sys_all_properties
43ff24c
+  fi
43ff24c
+  _values -s , "${_sys_all_properties[@]}"
43ff24c
+}
43ff24c
+
43ff24c
 _arguments -s \
43ff24c
     {-h,--help}'[Show help]' \
43ff24c
     '--version[Show package version]' \
43ff24c
     {-t+,--type=}'[List only units of a particular type]:unit type:_unit_types' \
43ff24c
     '--state=[Display units in the specifyied state]:unit state:_unit_states' \
43ff24c
-    \*{-p+,--property=}'[Show only properties by specific name]:unit property' \
43ff24c
+    {-p+,--property=}'[Show only properties by specific name]:unit property:_unit_properties' \
43ff24c
     {-a,--all}'[Show all units/properties, including dead/empty ones]' \
43ff24c
     '--reverse[Show reverse dependencies]' \
43ff24c
     '--after[Show units ordered after]' \