[arch-projects] [MKINITCPIO][PATCH 2/2] Add bash completion to mkinitcpio

Sebastien Luttringer seblu at seblu.net
Sat Jun 18 01:04:27 EDT 2011


It's annoying to remember the name of preset each time

Signed-off-by: Sebastien Luttringer <seblu at seblu.net>
---
 Makefile        |    4 +++-
 bash-completion |   20 ++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletions(-)
 create mode 100644 bash-completion

diff --git a/Makefile b/Makefile
index f06c3a4..03e02ff 100644
--- a/Makefile
+++ b/Makefile
@@ -33,6 +33,7 @@ install: all
 	cp -R mkinitcpio.d/* ${DESTDIR}/etc/mkinitcpio.d
 
 	install -D -m644 mkinitcpio.5.gz ${DESTDIR}/usr/share/man/man5/mkinitcpio.5.gz
+	install -D -m644 bash-completion ${DESTDIR}/etc/bash_completion.d/mkinitcpio
 
 doc: mkinitcpio.5.gz
 
@@ -61,7 +62,8 @@ TARBALL_FILES = \
 	mkinitcpio.conf \
 	mkinitcpio.d \
 	mkinitcpio.5.txt \
-	mkinitcpio.5.gz
+	mkinitcpio.5.gz \
+	bash-completion
 
 tarball: mkinitcpio.5.gz
 	mkdir -p build/mkinitcpio-${VERSION}
diff --git a/bash-completion b/bash-completion
new file mode 100644
index 0000000..49cd99e
--- /dev/null
+++ b/bash-completion
@@ -0,0 +1,20 @@
+# mkinitcpio bash completion by Seblu <seblu at seblu.net>
+
+_mkinitcpio ()
+{
+	local action="-c -k -s -b -g -a -p -m -S -v -M -L -H -h"
+	local cur="${COMP_WORDS[COMP_CWORD]}"
+	local caction="${COMP_WORDS[COMP_CWORD-1]}"
+	case "$caction" in
+		-c|-g|-s|-a) COMPREPLY=($(compgen -f -- $cur));;
+		-k) COMPREPLY=($(cd /lib/modules && compgen -d -- $cur));;
+		-b) COMPREPLY=($(compgen -d "$cur" -- $cur));;
+		-p) COMPREPLY=($(cd /etc/mkinitcpio.d/ && compgen -X '!*.preset' -f  -- $cur|sed 's/\.preset//'));;
+		-H|-S) COMPREPLY=($(cd /lib/initcpio/install/ && compgen -f -- $cur));;
+		-m) COMPREPLY=();;
+		*)	COMPREPLY=($(compgen -W "${action}" -- "$cur"));;
+	esac
+}
+complete -F _mkinitcpio mkinitcpio
+
+# vim: set ts=2 sw=2 ft=sh noet:
-- 
Sebastien "Seblu" Luttringer



More information about the arch-projects mailing list