96237b5
From 7f197e46c944bdb43fa1cedbd97708ac2ea72558 Mon Sep 17 00:00:00 2001
96237b5
From: Thomas Hindoe Paaboel Andersen <phomes@gmail.com>
96237b5
Date: Tue, 4 Mar 2014 23:16:30 +0100
96237b5
Subject: [PATCH] add bash completion for systemd-cat
96237b5
96237b5
(cherry picked from commit 207017017db91232189226bfcf29e61926310a9b)
96237b5
---
96237b5
 Makefile.am                       |  1 +
96237b5
 shell-completion/bash/systemd-cat | 57 +++++++++++++++++++++++++++++++++++++++
96237b5
 2 files changed, 58 insertions(+)
96237b5
 create mode 100644 shell-completion/bash/systemd-cat
96237b5
96237b5
diff --git a/Makefile.am b/Makefile.am
96237b5
index 834ed6f..7187b8d 100644
96237b5
--- a/Makefile.am
96237b5
+++ b/Makefile.am
96237b5
@@ -352,6 +352,7 @@ dist_bashcompletion_DATA = \
96237b5
 	shell-completion/bash/journalctl \
96237b5
 	shell-completion/bash/systemctl \
96237b5
 	shell-completion/bash/systemd-analyze \
96237b5
+	shell-completion/bash/systemd-cat \
96237b5
 	shell-completion/bash/systemd-cgls \
96237b5
 	shell-completion/bash/systemd-cgtop \
96237b5
 	shell-completion/bash/systemd-delta \
96237b5
diff --git a/shell-completion/bash/systemd-cat b/shell-completion/bash/systemd-cat
96237b5
new file mode 100644
96237b5
index 0000000..8d84042
96237b5
--- /dev/null
96237b5
+++ b/shell-completion/bash/systemd-cat
96237b5
@@ -0,0 +1,57 @@
96237b5
+# systemd-cat(1) completion                  -*- shell-script -*-
96237b5
+#
96237b5
+# This file is part of systemd.
96237b5
+#
96237b5
+# Copyright 2014 Thomas H.P. Andersen
96237b5
+#
96237b5
+# systemd is free software; you can redistribute it and/or modify it
96237b5
+# under the terms of the GNU Lesser General Public License as published by
96237b5
+# the Free Software Foundation; either version 2.1 of the License, or
96237b5
+# (at your option) any later version.
96237b5
+#
96237b5
+# systemd is distributed in the hope that it will be useful, but
96237b5
+# WITHOUT ANY WARRANTY; without even the implied warranty of
96237b5
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
96237b5
+# General Public License for more details.
96237b5
+#
96237b5
+# You should have received a copy of the GNU Lesser General Public License
96237b5
+# along with systemd; If not, see <http://www.gnu.org/licenses/>.
96237b5
+
96237b5
+__contains_word() {
96237b5
+        local w word=$1; shift
96237b5
+        for w in "$@"; do
96237b5
+                [[ $w = "$word" ]] && return
96237b5
+        done
96237b5
+}
96237b5
+
96237b5
+_systemd_cat() {
96237b5
+        local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
96237b5
+        local i verb comps
96237b5
+
96237b5
+        local -A OPTS=(
96237b5
+               [STANDALONE]='-h --help --version'
96237b5
+                      [ARG]='-t --identifier -p --priority --level-prefix'
96237b5
+        )
96237b5
+
96237b5
+        _init_completion || return
96237b5
+
96237b5
+        if __contains_word "$prev" ${OPTS[ARG]}; then
96237b5
+                case $prev in
96237b5
+                        --identifier|-t)
96237b5
+                                comps=''
96237b5
+                        ;;
96237b5
+                        --priority|-p)
96237b5
+                                comps='emerg alert crit err warning notice info debug'
96237b5
+                        ;;
96237b5
+                        --level-prefix)
96237b5
+                                comps='yes no'
96237b5
+                        ;;
96237b5
+                esac
96237b5
+                COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
96237b5
+                return 0
96237b5
+        fi
96237b5
+
96237b5
+        COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
96237b5
+}
96237b5
+
96237b5
+complete -F _systemd_cat systemd-cat