From 7f2b324b93bb152f5b9a1be6d15f12a46e5e9360 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sun, 26 Jun 2011 23:06:55 -0400 Subject: bash-completion: complete -k on kernel images Signed-off-by: Dave Reisner --- bash-completion | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bash-completion b/bash-completion index f4f8181..2a53c1a 100644 --- a/bash-completion +++ b/bash-completion @@ -11,6 +11,20 @@ _lsinitcpio () esac } +_find_kernel_versions() { + local -a matches + local regex + + regex="Linux kernel.*version" + while IFS=':' read -r file metadata; do + [[ $metadata =~ $regex ]] || continue + matches+=("$file") + done < <(file -e ascii /boot/*) + + COMPREPLY=($(cd /lib/modules && compgen -d -- $cur) + $(compgen -W "${matches[*]}" -- $cur)) +} + _mkinitcpio () { local action cur prev @@ -18,7 +32,7 @@ _mkinitcpio () _get_comp_words_by_ref cur prev case "$prev" in -c|-g) _filedir;; - -k) COMPREPLY=($(cd /lib/modules && compgen -d -- $cur));; + -k) _find_kernel_versions;; -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));; -- cgit v1.2.3-24-g4f1b