Harald Hoyer adf00e
From 7dbca9be866afd65d7ab5368250429e4291aaf88 Mon Sep 17 00:00:00 2001
Harald Hoyer adf00e
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer adf00e
Date: Tue, 16 Apr 2013 10:43:39 +0200
Harald Hoyer adf00e
Subject: [PATCH] lsinitrd: add bash completion
Harald Hoyer adf00e
Harald Hoyer adf00e
---
Harald Hoyer adf00e
 Makefile                    |  1 +
Harald Hoyer adf00e
 dracut.spec                 |  1 +
Harald Hoyer adf00e
 lsinitrd-bash-completion.sh | 63 +++++++++++++++++++++++++++++++++++++++++++++
Harald Hoyer adf00e
 3 files changed, 65 insertions(+)
Harald Hoyer adf00e
 create mode 100644 lsinitrd-bash-completion.sh
Harald Hoyer adf00e
Harald Hoyer adf00e
diff --git a/Makefile b/Makefile
Harald Hoyer adf00e
index d3798c6..e0baef2 100644
Harald Hoyer adf00e
--- a/Makefile
Harald Hoyer adf00e
+++ b/Makefile
Harald Hoyer adf00e
@@ -137,6 +137,7 @@ endif
Harald Hoyer adf00e
 	install -m 0755 51-dracut-rescue.install $(DESTDIR)${prefix}/lib/kernel/install.d/51-dracut-rescue.install
Harald Hoyer adf00e
 	mkdir -p $(DESTDIR)${bashcompletiondir}
Harald Hoyer adf00e
 	install -m 0644 dracut-bash-completion.sh $(DESTDIR)${bashcompletiondir}/dracut
Harald Hoyer adf00e
+	install -m 0644 lsinitrd-bash-completion.sh $(DESTDIR)${bashcompletiondir}/lsinitrd
Harald Hoyer adf00e
 
Harald Hoyer adf00e
 dracut-version.sh:
Harald Hoyer adf00e
 	@echo "DRACUT_VERSION=$(VERSION)$(GITVERSION)" > dracut-version.sh
Harald Hoyer adf00e
diff --git a/dracut.spec b/dracut.spec
Harald Hoyer adf00e
index cb605c6..197e9a0 100644
Harald Hoyer adf00e
--- a/dracut.spec
Harald Hoyer adf00e
+++ b/dracut.spec
Harald Hoyer adf00e
@@ -282,6 +282,7 @@ rm -rf $RPM_BUILD_ROOT
Harald Hoyer adf00e
 # compat symlink
Harald Hoyer adf00e
 /sbin/dracut
Harald Hoyer adf00e
 %{_datadir}/bash-completion/completions/dracut
Harald Hoyer adf00e
+%{_datadir}/bash-completion/completions/lsinitrd
Harald Hoyer adf00e
 %if 0%{?fedora} > 12 || 0%{?rhel} >= 6 || 0%{?suse_version} > 9999
Harald Hoyer adf00e
 %{_bindir}/mkinitrd
Harald Hoyer adf00e
 %{_bindir}/lsinitrd
Harald Hoyer adf00e
diff --git a/lsinitrd-bash-completion.sh b/lsinitrd-bash-completion.sh
Harald Hoyer adf00e
new file mode 100644
Harald Hoyer adf00e
index 0000000..78ab165
Harald Hoyer adf00e
--- /dev/null
Harald Hoyer adf00e
+++ b/lsinitrd-bash-completion.sh
Harald Hoyer adf00e
@@ -0,0 +1,63 @@
Harald Hoyer adf00e
+#!/bin/bash
Harald Hoyer adf00e
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
Harald Hoyer adf00e
+# ex: ts=8 sw=4 sts=4 et filetype=sh
Harald Hoyer adf00e
+#
Harald Hoyer adf00e
+# Copyright 2013 Red Hat, Inc.  All rights reserved.
Harald Hoyer adf00e
+#
Harald Hoyer adf00e
+# This program is free software; you can redistribute it and/or modify
Harald Hoyer adf00e
+# it under the terms of the GNU General Public License as published by
Harald Hoyer adf00e
+# the Free Software Foundation; either version 2 of the License, or
Harald Hoyer adf00e
+# (at your option) any later version.
Harald Hoyer adf00e
+#
Harald Hoyer adf00e
+# This program is distributed in the hope that it will be useful,
Harald Hoyer adf00e
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
Harald Hoyer adf00e
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Harald Hoyer adf00e
+# GNU General Public License for more details.
Harald Hoyer adf00e
+#
Harald Hoyer adf00e
+# You should have received a copy of the GNU General Public License
Harald Hoyer adf00e
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Harald Hoyer adf00e
+#
Harald Hoyer adf00e
+
Harald Hoyer adf00e
+__contains_word () {
Harald Hoyer adf00e
+        local word=$1; shift
Harald Hoyer adf00e
+        for w in $*; do [[ $w = $word ]] && return 0; done
Harald Hoyer adf00e
+        return 1
Harald Hoyer adf00e
+}
Harald Hoyer adf00e
+
Harald Hoyer adf00e
+_lsinitrd() {
Harald Hoyer adf00e
+        local field_vals= cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
Harald Hoyer adf00e
+        local -A OPTS=(
Harald Hoyer adf00e
+                [STANDALONE]='-s --size -h --help'
Harald Hoyer adf00e
+
Harald Hoyer adf00e
+                       [ARG]='-f --file -k --kver'
Harald Hoyer adf00e
+        )
Harald Hoyer adf00e
+
Harald Hoyer adf00e
+        if __contains_word "$prev" ${OPTS[ARG]}; then
Harald Hoyer adf00e
+                case $prev in
Harald Hoyer adf00e
+                        --file|-f)
Harald Hoyer adf00e
+                                comps=$(compgen -f -- "$cur")
Harald Hoyer adf00e
+                                compopt -o filenames
Harald Hoyer adf00e
+                        ;;
Harald Hoyer adf00e
+                        --kver|-k)
Harald Hoyer adf00e
+                                comps=$(cd /lib/modules; echo [0-9]*)
Harald Hoyer adf00e
+                        ;;
Harald Hoyer adf00e
+                        *)
Harald Hoyer adf00e
+                                return 0
Harald Hoyer adf00e
+                        ;;
Harald Hoyer adf00e
+                esac
Harald Hoyer adf00e
+                COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
Harald Hoyer adf00e
+                return 0
Harald Hoyer adf00e
+        fi
Harald Hoyer adf00e
+
Harald Hoyer adf00e
+        if [[ $cur = -* ]]; then
Harald Hoyer adf00e
+                COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
Harald Hoyer adf00e
+                return 0
Harald Hoyer adf00e
+        fi
Harald Hoyer adf00e
+
Harald Hoyer adf00e
+        comps=$(compgen -f -- "$cur")
Harald Hoyer adf00e
+        compopt -o filenames
Harald Hoyer adf00e
+        COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
Harald Hoyer adf00e
+        return 0
Harald Hoyer adf00e
+}
Harald Hoyer adf00e
+
Harald Hoyer adf00e
+complete -F _lsinitrd lsinitrd