summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--bash-completion32
-rwxr-xr-xmkinitcpio16
3 files changed, 45 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 0c86ac0..ff81525 100644
--- a/Makefile
+++ b/Makefile
@@ -40,6 +40,7 @@ install: all
install -m644 -t ${DESTDIR}/etc/mkinitcpio.d mkinitcpio.d/*
install -m644 mkinitcpio.5 ${DESTDIR}/usr/share/man/man5/mkinitcpio.5
+ install -m644 bash-completion ${DESTDIR}/etc/bash_completion.d/mkinitcpio
doc: mkinitcpio.5
mkinitcpio.5: mkinitcpio.5.txt Makefile
diff --git a/bash-completion b/bash-completion
new file mode 100644
index 0000000..50cbb8e
--- /dev/null
+++ b/bash-completion
@@ -0,0 +1,32 @@
+# mkinitcpio bash completion by Seblu <seblu@seblu.net>
+
+_lsinitcpio ()
+{
+ local action="-a -h -v -x"
+ local cur="${COMP_WORDS[COMP_CWORD]}"
+ local caction="${COMP_WORDS[COMP_CWORD]}"
+ case "$caction" in
+ -*) COMPREPLY=($(compgen -W "${action}" -- "$cur"));;
+ *) _filedir;;
+ esac
+}
+
+_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) _filedir;;
+ -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
+complete -F _lsinitcpio lsinitcpio
+
+# vim: set ts=2 sw=2 ft=sh noet:
diff --git a/mkinitcpio b/mkinitcpio
index 4082ba5..7a30be0 100755
--- a/mkinitcpio
+++ b/mkinitcpio
@@ -118,8 +118,16 @@ while getopts ':c:k:sb:g:p:m:nvH:LMhS:t:z:' arg; do
IFS=${OLDIFS}
unset OLDIFS
;;
- H) . "${INSTDIR}/${OPTARG}";
- msg "Help for hook '${OPTARG}'"
+ H) if [[ ! -r "${INSTDIR}/${OPTARG}" ]]; then
+ error "No hook ${OPTARG}"
+ exit 1
+ fi
+ . "${INSTDIR}/${OPTARG}"
+ if [[ $(type -t help) != function ]]; then
+ error "No help for hook ${OPTARG}"
+ exit 1
+ fi
+ echo "Help for hook '${OPTARG}':"
help
exit 0 ;;
L) msg "Available hooks"
@@ -129,9 +137,9 @@ while getopts ':c:k:sb:g:p:m:nvH:LMhS:t:z:' arg; do
M) SHOW_AUTOMODS=1 ;;
t) TMPDIR=$OPTARG ;;
z) optcompress=$OPTARG ;;
- :) echo "error: option requires an argument -- '$OPTARG'" >&2
+ :) error "option requires an argument -- '$OPTARG'" >&2
exit 1 ;;
- \?) echo "error: invalid option -- '$OPTARG'" >&2
+ \?) error "invalid option -- '$OPTARG'" >&2
exit 1 ;;
esac
done