a52f674
From 7d6ed8b92b7490ddf419d2782d3d8a0d6f827cc7 Mon Sep 17 00:00:00 2001
a52f674
From: Thomas Hindoe Paaboel Andersen <phomes@gmail.com>
a52f674
Date: Sat, 1 Mar 2014 23:08:38 +0100
a52f674
Subject: [PATCH] add bash completion for systemd-cgls
a52f674
a52f674
(cherry picked from commit abdab4f602745952030a37b1521cd0374d51d3ea)
a52f674
---
a52f674
 Makefile.am                        |  1 +
a52f674
 shell-completion/bash/systemd-cgls | 56 ++++++++++++++++++++++++++++++++++++++
a52f674
 2 files changed, 57 insertions(+)
a52f674
 create mode 100644 shell-completion/bash/systemd-cgls
a52f674
a52f674
diff --git a/Makefile.am b/Makefile.am
a52f674
index 03a1f91..d4a65e7 100644
a52f674
--- a/Makefile.am
a52f674
+++ b/Makefile.am
a52f674
@@ -342,6 +342,7 @@ dist_bashcompletion_DATA = \
a52f674
 	shell-completion/bash/journalctl \
a52f674
 	shell-completion/bash/systemctl \
a52f674
 	shell-completion/bash/systemd-analyze \
a52f674
+	shell-completion/bash/systemd-cgls \
a52f674
 	shell-completion/bash/systemd-delta \
a52f674
 	shell-completion/bash/systemd-nspawn \
a52f674
 	shell-completion/bash/systemd-run \
a52f674
diff --git a/shell-completion/bash/systemd-cgls b/shell-completion/bash/systemd-cgls
a52f674
new file mode 100644
a52f674
index 0000000..0570438
a52f674
--- /dev/null
a52f674
+++ b/shell-completion/bash/systemd-cgls
a52f674
@@ -0,0 +1,56 @@
a52f674
+# systemd-cgls(1) completion                  -*- shell-script -*-
a52f674
+#
a52f674
+# This file is part of systemd.
a52f674
+#
a52f674
+# Copyright 2014 Thomas H.P. Andersen
a52f674
+#
a52f674
+# systemd is free software; you can redistribute it and/or modify it
a52f674
+# under the terms of the GNU Lesser General Public License as published by
a52f674
+# the Free Software Foundation; either version 2.1 of the License, or
a52f674
+# (at your option) any later version.
a52f674
+#
a52f674
+# systemd is distributed in the hope that it will be useful, but
a52f674
+# WITHOUT ANY WARRANTY; without even the implied warranty of
a52f674
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a52f674
+# General Public License for more details.
a52f674
+#
a52f674
+# You should have received a copy of the GNU Lesser General Public License
a52f674
+# along with systemd; If not, see <http://www.gnu.org/licenses/>.
a52f674
+
a52f674
+__contains_word() {
a52f674
+        local w word=$1; shift
a52f674
+        for w in "$@"; do
a52f674
+                [[ $w = "$word" ]] && return
a52f674
+        done
a52f674
+}
a52f674
+
a52f674
+__get_machines() {
a52f674
+        local a b
a52f674
+        machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
a52f674
+}
a52f674
+
a52f674
+_systemd_cgls() {
a52f674
+        local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
a52f674
+        local i verb comps
a52f674
+
a52f674
+        local -A OPTS=(
a52f674
+               [STANDALONE]='-h --help --version --all -l --full -k --no-pager'
a52f674
+                      [ARG]='-M --machine'
a52f674
+        )
a52f674
+
a52f674
+        _init_completion || return
a52f674
+
a52f674
+        if __contains_word "$prev" ${OPTS[ARG]}; then
a52f674
+                case $prev in
a52f674
+                        --machine|-M)
a52f674
+                                comps=$( __get_machines )
a52f674
+                        ;;
a52f674
+                esac
a52f674
+                COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
a52f674
+                return 0
a52f674
+        fi
a52f674
+
a52f674
+        COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
a52f674
+}
a52f674
+
a52f674
+complete -F _systemd_cgls systemd-cgls