[systemd-devel] [PATCH] shell-completion: Make bash completion show user units if --user is entered.

Gary van der Merwe garyvdm at gmail.com
Mon Apr 8 01:19:00 PDT 2013


This patch makes the bash shell-completion show user units if --user is all
ready entered in the command line.

I really want to do the same for the zsh completion (as this is what I use,)
but I got horribaly stuck. 

---
 shell-completion/bash/systemctl | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/shell-completion/bash/systemctl b/shell-completion/bash/systemctl
index 27d89ec..96eae0e 100644
--- a/shell-completion/bash/systemctl
+++ b/shell-completion/bash/systemctl
@@ -18,7 +18,11 @@
 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
 
 __systemctl() {
-        systemctl --full --no-legend "$@"
+        if [ $_systemctl_is_user -eq 1 ]; then
+                systemctl --full --no-legend "$@"
+        else
+                systemctl --user --full --no-legend "$@"
+        fi
 }
 
 __contains_word () {
@@ -59,6 +63,9 @@ _systemctl () {
         local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
         local i verb comps
 
+        __contains_word "--user" ${COMP_WORDS[*]}
+        _systemctl_is_user=$?
+
         local -A OPTS=(
                [STANDALONE]='--all -a --defaults --fail --ignore-dependencies --failed --force -f --full --global
                              --help -h --no-ask-password --no-block --no-legend --no-pager --no-reload --no-wall
-- 
1.8.2



More information about the systemd-devel mailing list