Blame 0023-add-dracut-bash-completion.sh.patch

Harald Hoyer a20c0e
From 917f3e4d25784cbd1490fc4f27e6246d98987987 Mon Sep 17 00:00:00 2001
Harald Hoyer a20c0e
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer a20c0e
Date: Wed, 13 Mar 2013 12:46:16 +0100
Harald Hoyer a20c0e
Subject: [PATCH] add dracut-bash-completion.sh
Harald Hoyer a20c0e
Harald Hoyer a20c0e
---
Harald Hoyer a20c0e
 Makefile                  |  3 +++
Harald Hoyer a20c0e
 dracut-bash-completion.sh | 68 +++++++++++++++++++++++++++++++++++++++++++++++
Harald Hoyer a20c0e
 dracut.spec               |  1 +
Harald Hoyer a20c0e
 3 files changed, 72 insertions(+)
Harald Hoyer a20c0e
 create mode 100644 dracut-bash-completion.sh
Harald Hoyer a20c0e
Harald Hoyer a20c0e
diff --git a/Makefile b/Makefile
Harald Hoyer a20c0e
index a11689c..644d17d 100644
Harald Hoyer a20c0e
--- a/Makefile
Harald Hoyer a20c0e
+++ b/Makefile
Harald Hoyer a20c0e
@@ -12,6 +12,7 @@ bindir ?= ${prefix}/bin
Harald Hoyer a20c0e
 mandir ?= ${prefix}/share/man
Harald Hoyer a20c0e
 CFLAGS ?= -O2 -g -Wall
Harald Hoyer a20c0e
 CFLAGS += -std=gnu99
Harald Hoyer a20c0e
+bashcompletiondir ?= ${datadir}/bash-completion/completions
Harald Hoyer a20c0e
 
Harald Hoyer a20c0e
 man1pages = lsinitrd.1
Harald Hoyer a20c0e
 
Harald Hoyer a20c0e
@@ -119,6 +120,8 @@ endif
Harald Hoyer a20c0e
 	mkdir -p $(DESTDIR)${prefix}/lib/kernel/install.d
Harald Hoyer a20c0e
 	install -m 0755 50-dracut.install $(DESTDIR)${prefix}/lib/kernel/install.d/50-dracut.install
Harald Hoyer a20c0e
 	install -m 0755 51-dracut-rescue.install $(DESTDIR)${prefix}/lib/kernel/install.d/51-dracut-rescue.install
Harald Hoyer a20c0e
+	mkdir -p $(DESTDIR)${bashcompletiondir}
Harald Hoyer a20c0e
+	install -m 0644 dracut-bash-completion.sh $(DESTDIR)${bashcompletiondir}/dracut
Harald Hoyer a20c0e
 
Harald Hoyer a20c0e
 dracut-version.sh:
Harald Hoyer a20c0e
 	@echo "DRACUT_VERSION=$(VERSION)-$(GITVERSION)" > dracut-version.sh
Harald Hoyer a20c0e
diff --git a/dracut-bash-completion.sh b/dracut-bash-completion.sh
Harald Hoyer a20c0e
new file mode 100644
Harald Hoyer a20c0e
index 0000000..da067c5
Harald Hoyer a20c0e
--- /dev/null
Harald Hoyer a20c0e
+++ b/dracut-bash-completion.sh
Harald Hoyer a20c0e
@@ -0,0 +1,68 @@
Harald Hoyer a20c0e
+#!/bin/bash
Harald Hoyer a20c0e
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
Harald Hoyer a20c0e
+# ex: ts=8 sw=4 sts=4 et filetype=sh
Harald Hoyer a20c0e
+#
Harald Hoyer a20c0e
+# Copyright 2013 Red Hat, Inc.  All rights reserved.
Harald Hoyer a20c0e
+#
Harald Hoyer a20c0e
+# This program is free software; you can redistribute it and/or modify
Harald Hoyer a20c0e
+# it under the terms of the GNU General Public License as published by
Harald Hoyer a20c0e
+# the Free Software Foundation; either version 2 of the License, or
Harald Hoyer a20c0e
+# (at your option) any later version.
Harald Hoyer a20c0e
+#
Harald Hoyer a20c0e
+# This program is distributed in the hope that it will be useful,
Harald Hoyer a20c0e
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
Harald Hoyer a20c0e
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Harald Hoyer a20c0e
+# GNU General Public License for more details.
Harald Hoyer a20c0e
+#
Harald Hoyer a20c0e
+# You should have received a copy of the GNU General Public License
Harald Hoyer a20c0e
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Harald Hoyer a20c0e
+#
Harald Hoyer a20c0e
+
Harald Hoyer a20c0e
+__contains_word () {
Harald Hoyer a20c0e
+        local word=$1; shift
Harald Hoyer a20c0e
+        for w in $*; do [[ $w = $word ]] && return 0; done
Harald Hoyer a20c0e
+        return 1
Harald Hoyer a20c0e
+}
Harald Hoyer a20c0e
+
Harald Hoyer a20c0e
+_dracut() {
Harald Hoyer a20c0e
+        local field_vals= cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
Harald Hoyer a20c0e
+        local -A OPTS=(
Harald Hoyer a20c0e
+                [STANDALONE]='-f -v -q -l -H -h -M -N
Harald Hoyer a20c0e
+                              --ro-mnt --force --kernel-only --no-kernel --strip --nostrip
Harald Hoyer a20c0e
+                              --hardlink --nohardlink --noprefix --mdadmconf --nomdadmconf
Harald Hoyer a20c0e
+                              --lvmconf --nolvmconf --debug --profile --verbose --quiet
Harald Hoyer a20c0e
+                              --local --hostonly --no-hostonly --fstab --help --bzip2 --lzma
Harald Hoyer a20c0e
+                              --xz --no-compress --gzip --list-modules --show-modules --keep
Harald Hoyer a20c0e
+                              --printsize --regenerate-all'
Harald Hoyer a20c0e
+
Harald Hoyer a20c0e
+                       [ARG]='-a -m -o -d -I -k -c -L --kver --add --force-add --add-drivers
Harald Hoyer a20c0e
+                              --omit-drivers --modules --omit --drivers --filesystems --install
Harald Hoyer a20c0e
+                              --fwdir --libdirs --fscks --add-fstab --mount --device --nofscks
Harald Hoyer a20c0e
+                              --kmoddir --conf --confdir --tmpdir --stdlog --compress --prefix
Harald Hoyer a20c0e
+                              --kernel-cmdline --sshkey'
Harald Hoyer a20c0e
+        )
Harald Hoyer a20c0e
+
Harald Hoyer a20c0e
+        if __contains_word "$prev" ${OPTS[ARG]}; then
Harald Hoyer a20c0e
+                case $prev in
Harald Hoyer a20c0e
+                        --kmoddir|-k|--fwdir|-c|--conf|--confdir|--tmpdir|--sshkey|--add-fstab|--add-device|-I|--install)
Harald Hoyer a20c0e
+                                comps=$(compgen -d -- "$cur")
Harald Hoyer a20c0e
+                                compopt -o filenames
Harald Hoyer a20c0e
+                        ;;
Harald Hoyer a20c0e
+                        -a|-m|-o|--add|--modules|--omit)
Harald Hoyer a20c0e
+                                comps=$(dracut --list-modules 2>/dev/null)
Harald Hoyer a20c0e
+                        ;;
Harald Hoyer a20c0e
+                        *)
Harald Hoyer a20c0e
+                                return 0
Harald Hoyer a20c0e
+                        ;;
Harald Hoyer a20c0e
+                esac
Harald Hoyer a20c0e
+                COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
Harald Hoyer a20c0e
+                return 0
Harald Hoyer a20c0e
+        fi
Harald Hoyer a20c0e
+
Harald Hoyer a20c0e
+        if [[ $cur = -* ]]; then
Harald Hoyer a20c0e
+                COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
Harald Hoyer a20c0e
+                return 0
Harald Hoyer a20c0e
+        fi
Harald Hoyer a20c0e
+}
Harald Hoyer a20c0e
+
Harald Hoyer a20c0e
+complete -F _dracut dracut
Harald Hoyer a20c0e
diff --git a/dracut.spec b/dracut.spec
Harald Hoyer a20c0e
index 06149de..418baf4 100644
Harald Hoyer a20c0e
--- a/dracut.spec
Harald Hoyer a20c0e
+++ b/dracut.spec
Harald Hoyer a20c0e
@@ -277,6 +277,7 @@ rm -rf $RPM_BUILD_ROOT
Harald Hoyer a20c0e
 %{_bindir}/dracut
Harald Hoyer a20c0e
 # compat symlink
Harald Hoyer a20c0e
 /sbin/dracut
Harald Hoyer a20c0e
+%{_datadir}/bash-completion/completions/dracut
Harald Hoyer a20c0e
 %if 0%{?fedora} > 12 || 0%{?rhel} >= 6 || 0%{?suse_version} > 9999
Harald Hoyer a20c0e
 %{_bindir}/mkinitrd
Harald Hoyer a20c0e
 %{_bindir}/lsinitrd