From b130e5d9f622c05863a889052d7bf9eac5c0af58 Mon Sep 17 00:00:00 2001 From: Sebastien Luttringer Date: Sat, 18 Jun 2011 06:49:30 +0200 Subject: Add bash completion to mkinitcpio It's annoying to remember the name of preset each time Signed-off-by: Sebastien Luttringer --- Makefile | 1 + bash-completion | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 bash-completion diff --git a/Makefile b/Makefile index b77e088..4068f23 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 diff --git a/bash-completion b/bash-completion new file mode 100644 index 0000000..ddb60e2 --- /dev/null +++ b/bash-completion @@ -0,0 +1,20 @@ +# mkinitcpio bash completion by Seblu + +_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 + +# vim: set ts=2 sw=2 ft=sh noet: -- cgit v1.2.3-24-g4f1b From 3a65dbdaf17ff26691559fd224e66b2fbe3eee7c Mon Sep 17 00:00:00 2001 From: Sebastien Luttringer Date: Sat, 18 Jun 2011 06:56:55 +0200 Subject: Fix printing of bash usage when asking for a bad hook before: mkinitcpio -H sex /sbin/mkinitcpio: line 105: /lib/initcpio/install/sex: No such file or directory Help for hook 'sex': GNU bash, version 4.2.10(2)-release (x86_64-unknown-linux-gnu) These shell commands are defined internally. Type `help' to see this list. after: mkinitcpio -H sex ==> ERROR: No hook sex Signed-off-by: Sebastien Luttringer --- mkinitcpio | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mkinitcpio b/mkinitcpio index 4082ba5..bd1a4c8 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -118,8 +118,12 @@ 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}" + echo "Help for hook '${OPTARG}':" help exit 0 ;; L) msg "Available hooks" -- cgit v1.2.3-24-g4f1b From 643da24974067821638fd27d0f9685dffb525f21 Mon Sep 17 00:00:00 2001 From: Sebastien Luttringer Date: Sun, 26 Jun 2011 19:29:13 +0200 Subject: Print pretty message if no help is defined in hook Thanks to Dave Reisner for having suggested! Signed-off-by: Sebastien Luttringer --- mkinitcpio | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mkinitcpio b/mkinitcpio index bd1a4c8..a9c75ed 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -123,6 +123,10 @@ while getopts ':c:k:sb:g:p:m:nvH:LMhS:t:z:' arg; do 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 ;; -- cgit v1.2.3-24-g4f1b From 10986ecadeb7cc3ac39fa55f2c4a873b54323f2f Mon Sep 17 00:00:00 2001 From: Sebastien Luttringer Date: Sun, 26 Jun 2011 20:19:04 +0200 Subject: Use error function instead of echo Signed-off-by: Sebastien Luttringer --- mkinitcpio | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mkinitcpio b/mkinitcpio index a9c75ed..7a30be0 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -137,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 -- cgit v1.2.3-24-g4f1b From f58be6cc8d802c4c48edd594aab41408df30e954 Mon Sep 17 00:00:00 2001 From: Sebastien Luttringer Date: Sun, 26 Jun 2011 23:15:29 +0200 Subject: Add lsinitcpio bash completion Signed-off-by: Sebastien Luttringer --- bash-completion | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bash-completion b/bash-completion index ddb60e2..50cbb8e 100644 --- a/bash-completion +++ b/bash-completion @@ -1,5 +1,16 @@ # mkinitcpio bash completion by Seblu +_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" @@ -16,5 +27,6 @@ _mkinitcpio () esac } complete -F _mkinitcpio mkinitcpio +complete -F _lsinitcpio lsinitcpio # vim: set ts=2 sw=2 ft=sh noet: -- cgit v1.2.3-24-g4f1b