[arch-projects] [MKINITCPIO][PATCH 1/2] 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 No such hook: sex Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- mkinitcpio | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/mkinitcpio b/mkinitcpio index 70710eb..7b8f503 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -102,7 +102,8 @@ while getopts ':c:k:s:b:g:a:p:m:vH:LMhS:' arg; do IFS=${OLDIFS} unset OLDIFS ;; - H) . "${INSTDIR}/${OPTARG}"; + H) [[ ! -r "${INSTDIR}/${OPTARG}" ]] && echo "No such hook: ${OPTARG}" && exit 1 + . "${INSTDIR}/${OPTARG}"; echo "Help for hook '${OPTARG}':" help cleanup -- Sebastien "Seblu" Luttringer
It's annoying to remember the name of preset each time Signed-off-by: Sebastien Luttringer <seblu@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@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
On Sat, Jun 18, 2011 at 07:04:26AM +0200, Sebastien Luttringer wrote:
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 No such hook: sex
Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- mkinitcpio | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/mkinitcpio b/mkinitcpio index 70710eb..7b8f503 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -102,7 +102,8 @@ while getopts ':c:k:s:b:g:a:p:m:vH:LMhS:' arg; do IFS=${OLDIFS} unset OLDIFS ;; - H) . "${INSTDIR}/${OPTARG}"; + H) [[ ! -r "${INSTDIR}/${OPTARG}" ]] && echo "No such hook: ${OPTARG}" && exit 1 + . "${INSTDIR}/${OPTARG}"; echo "Help for hook '${OPTARG}':" help cleanup -- Sebastien "Seblu" Luttringer
If we're going to check this (and I agree we should -- was about to push my own patch), there should be a check to make sure 'help' exists as a function as well after sourcing the hook. d
On Mon, Jun 20, 2011 at 12:25 AM, Dave Reisner <d@falconindy.com> wrote:
On Sat, Jun 18, 2011 at 07:04:26AM +0200, Sebastien Luttringer wrote:
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 No such hook: sex
Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- mkinitcpio | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/mkinitcpio b/mkinitcpio index 70710eb..7b8f503 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -102,7 +102,8 @@ while getopts ':c:k:s:b:g:a:p:m:vH:LMhS:' arg; do IFS=${OLDIFS} unset OLDIFS ;; - H) . "${INSTDIR}/${OPTARG}"; + H) [[ ! -r "${INSTDIR}/${OPTARG}" ]] && echo "No such hook: ${OPTARG}" && exit 1 + . "${INSTDIR}/${OPTARG}"; echo "Help for hook '${OPTARG}':" help cleanup -- Sebastien "Seblu" Luttringer
If we're going to check this (and I agree we should -- was about to push my own patch), there should be a check to make sure 'help' exists as a function as well after sourcing the hook.
I asked but I said we should consider hooks files valid because it's like this everywhere in scripts. like here if [ "${SHOW_AUTOMODS}" = "y" ]; then echo "Modules autodetected:" . "${INSTDIR}/autodetect" install cat "${MODULE_FILE}" -- Sébastien Luttringer www.seblu.net
On Mon, Jun 20, 2011 at 12:54:08AM +0200, Seblu wrote:
On Mon, Jun 20, 2011 at 12:25 AM, Dave Reisner <d@falconindy.com> wrote:
On Sat, Jun 18, 2011 at 07:04:26AM +0200, Sebastien Luttringer wrote:
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 No such hook: sex
Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- mkinitcpio | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/mkinitcpio b/mkinitcpio index 70710eb..7b8f503 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -102,7 +102,8 @@ while getopts ':c:k:s:b:g:a:p:m:vH:LMhS:' arg; do IFS=${OLDIFS} unset OLDIFS ;; - H) . "${INSTDIR}/${OPTARG}"; + H) [[ ! -r "${INSTDIR}/${OPTARG}" ]] && echo "No such hook: ${OPTARG}" && exit 1 + . "${INSTDIR}/${OPTARG}"; echo "Help for hook '${OPTARG}':" help cleanup -- Sebastien "Seblu" Luttringer
If we're going to check this (and I agree we should -- was about to push my own patch), there should be a check to make sure 'help' exists as a function as well after sourcing the hook.
I asked but I said we should consider hooks files valid because it's like this everywhere in scripts.
like here if [ "${SHOW_AUTOMODS}" = "y" ]; then echo "Modules autodetected:" . "${INSTDIR}/autodetect" install cat "${MODULE_FILE}"
-- Sébastien Luttringer www.seblu.net
An install hook isn't much without an install function (soon to be build, perhaps?). You can get away without defining a help function and still have a useful install hook. d
On Mon, Jun 20, 2011 at 1:50 AM, Dave Reisner <d@falconindy.com> wrote:
On Mon, Jun 20, 2011 at 12:54:08AM +0200, Seblu wrote:
On Mon, Jun 20, 2011 at 12:25 AM, Dave Reisner <d@falconindy.com> wrote:
On Sat, Jun 18, 2011 at 07:04:26AM +0200, Sebastien Luttringer wrote:
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 No such hook: sex
Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- mkinitcpio | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/mkinitcpio b/mkinitcpio index 70710eb..7b8f503 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -102,7 +102,8 @@ while getopts ':c:k:s:b:g:a:p:m:vH:LMhS:' arg; do IFS=${OLDIFS} unset OLDIFS ;; - H) . "${INSTDIR}/${OPTARG}"; + H) [[ ! -r "${INSTDIR}/${OPTARG}" ]] && echo "No such hook: ${OPTARG}" && exit 1 + . "${INSTDIR}/${OPTARG}"; echo "Help for hook '${OPTARG}':" help cleanup -- Sebastien "Seblu" Luttringer
If we're going to check this (and I agree we should -- was about to push my own patch), there should be a check to make sure 'help' exists as a function as well after sourcing the hook.
I asked but I said we should consider hooks files valid because it's like this everywhere in scripts.
like here if [ "${SHOW_AUTOMODS}" = "y" ]; then echo "Modules autodetected:" . "${INSTDIR}/autodetect" install cat "${MODULE_FILE}"
-- Sébastien Luttringer www.seblu.net
An install hook isn't much without an install function (soon to be build, perhaps?). You can get away without defining a help function and still have a useful install hook.
ok right. -- Sébastien Luttringer www.seblu.net
Am 20.06.2011 00:25, schrieb Dave Reisner:
On Sat, Jun 18, 2011 at 07:04:26AM +0200, Sebastien Luttringer wrote:
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 No such hook: sex
Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- mkinitcpio | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/mkinitcpio b/mkinitcpio index 70710eb..7b8f503 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -102,7 +102,8 @@ while getopts ':c:k:s:b:g:a:p:m:vH:LMhS:' arg; do IFS=${OLDIFS} unset OLDIFS ;; - H) . "${INSTDIR}/${OPTARG}"; + H) [[ ! -r "${INSTDIR}/${OPTARG}" ]] && echo "No such hook: ${OPTARG}" && exit 1 + . "${INSTDIR}/${OPTARG}"; echo "Help for hook '${OPTARG}':" help cleanup -- Sebastien "Seblu" Luttringer
If we're going to check this (and I agree we should -- was about to push my own patch), there should be a check to make sure 'help' exists as a function as well after sourcing the hook.
d
I am applying this as-is, we can complete this check later.
Can you rebase those patches upon Dave's work which I'll push in a minute?
participants (4)
-
Dave Reisner
-
Sebastien Luttringer
-
Seblu
-
Thomas Bächler