[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.90-133-g3388314
Igor Murzov
e-mail at date.by
Thu Jan 12 20:33:56 UTC 2012
The following commit has been merged in the master branch:
commit f67818e023f9afbeef8698fdd3c08eb0f90ad468
Author: Igor Murzov <e-mail at date.by>
Date: Thu Jan 12 19:30:56 2012 +0400
modprobe, modinfo, insmod: Move modprobe and modinfo completions to their own files.
Also fix some options handling and errors in unusual usecases (Alioth: #313498).
Patch is partially written by Lekensteyn <lekensteyn at gmail.com>
Reviewed-by: Sergey V <sftp.mtuci at gmail.com>
diff --git a/completions/.gitignore b/completions/.gitignore
index 0e234de..b2a60e7 100644
--- a/completions/.gitignore
+++ b/completions/.gitignore
@@ -83,8 +83,6 @@ mailsnarf
mdecrypt
mencoder
mkisofs
-modinfo
-modprobe
mogrify
montage
mplayer2
diff --git a/completions/Makefile.am b/completions/Makefile.am
index 6e0f56f..34f2abd 100644
--- a/completions/Makefile.am
+++ b/completions/Makefile.am
@@ -193,6 +193,8 @@ bashcomp_DATA = a2x \
mkinitrd \
mktemp \
mmsitepass \
+ modinfo \
+ modprobe \
monodevelop \
mount \
mount.linux \
@@ -433,8 +435,6 @@ CLEANFILES = \
mdecrypt \
mencoder \
mkisofs \
- modinfo \
- modprobe \
mogrify \
montage \
mplayer2 \
@@ -639,10 +639,6 @@ symlinks:
rm -f $(targetdir)/$$file && \
$(LN_S) info $(targetdir)/$$file ; \
done
- for file in modprobe modinfo ; do \
- rm -f $(targetdir)/$$file && \
- $(LN_S) insmod $(targetdir)/$$file ; \
- done
for file in javac javadoc ; do \
rm -f $(targetdir)/$$file && \
$(LN_S) java $(targetdir)/$$file ; \
diff --git a/completions/insmod b/completions/insmod
index 725678e..2084085 100644
--- a/completions/insmod
+++ b/completions/insmod
@@ -1,34 +1,18 @@
-# Linux insmod(8), modprobe(8) and modinfo(8) completion -*- shell-script -*-
-# This completes on the list of all available modules for the version of the
-# kernel currently running.
-#
+# Linux insmod(8) completion -*- shell-script -*-
+
_insmod()
{
local cur prev words cword
_init_completion || return
- # behave like lsmod for modprobe -r
- if [[ ${1##*/} == modprobe && "${words[1]}" == -r ]]; then
- _installed_modules "$cur"
- return 0
- fi
-
- # do filename completion if we're giving a path to a module
- if [[ "$cur" == @(*/|[.~])* ]]; then
+ # do filename completion for first argument
+ if [[ $cword -eq 1 ]]; then
_filedir '@(?(k)o?(.gz))'
- return 0
+ else # do module parameter completion
+ COMPREPLY=( $( compgen -W "$( /sbin/modinfo -p ${words[1]} \
+ 2>/dev/null | cut -d: -f1 )" -- "$cur" ) )
fi
-
- if [[ $cword -gt 1 && "${words[cword-1]}" != -* ]]; then
- # do module parameter completion
- COMPREPLY=( $( compgen -W "$( /sbin/modinfo -p ${words[1]} | \
- cut -d: -f1 )" -- "$cur" ) )
- else
- _modules $(uname -r)
- fi
-
- return 0
} &&
-complete -F _insmod insmod modprobe modinfo
+complete -F _insmod insmod
# ex: ts=4 sw=4 et filetype=sh
diff --git a/completions/modinfo b/completions/modinfo
new file mode 100644
index 0000000..2a35987
--- /dev/null
+++ b/completions/modinfo
@@ -0,0 +1,44 @@
+# Linux modinfo(8) completion -*- shell-script -*-
+
+_modinfo()
+{
+ local cur prev words cword
+ _init_completion || return
+
+ case "$prev" in
+ -F|--field)
+ COMPREPLY=( $( compgen -W 'alias author depends description
+ filename firmware license parm srcversion staging vermagic
+ version' -- "$(echo "$cur" | tr '[:upper:]' '[:lower:]')" ) )
+ return
+ ;;
+ -k)
+ _kernel_versions
+ return
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-V --version -F --field -k -0 --null -a -d
+ -l -p -n' -- "$cur" ) )
+ return
+ fi
+
+ local i version=$(uname -r)
+ for (( i=${#words[@]}-1; i>0; i-- )); do
+ if [[ ${words[i]} == -k ]]; then
+ version=${words[i+1]}
+ break
+ fi
+ done
+
+ # do filename completion if we're giving a path to a module
+ if [[ "$cur" == @(*/|[.~])* ]]; then
+ _filedir '@(?(k)o?(.gz))'
+ else
+ _modules $version
+ fi
+} &&
+complete -F _modinfo modinfo
+
+# ex: ts=4 sw=4 et filetype=sh
diff --git a/completions/modprobe b/completions/modprobe
new file mode 100644
index 0000000..6db1b35
--- /dev/null
+++ b/completions/modprobe
@@ -0,0 +1,86 @@
+# Linux modprobe(8) completion -*- shell-script -*-
+
+_modprobe()
+{
+ local cur prev words cword
+ _init_completion || return
+
+ case "$prev" in
+ -C|--config)
+ _filedir
+ return
+ ;;
+ -d|--dirname|-t|--type)
+ _filedir -d
+ return
+ ;;
+ -S|--set-version)
+ _kernel_versions
+ return
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-a --all -b --use-blacklist -C --config -c
+ --showconfig --dump-modversions -d --dirname --first-time
+ --force-vermagic --force-modversion -f --force -i --ignore-install
+ --ignore-remove -l --list -n --dry-run -q --quiet -R
+ --resolve-alias -r --remove -S --set-version --show-depends -s
+ --syslog -t --type -V --version -v --verbose' -- "$cur" ) )
+ return
+ fi
+
+ local i mode=insert module= version=$(uname -r)
+ for (( i=1; i < $cword; i++ )); do
+ case "${words[i]}" in
+ -r|--remove)
+ mode=remove
+ ;;
+ -l|--list)
+ mode=list
+ ;;
+ --dump-modversions)
+ mode=file
+ ;;
+ -S|--set-version)
+ version=${words[i+1]} # -S is not $prev and not $cur
+ ;;
+ -C|--config|-d|--dirname|-t|--type)
+ ((i++)) # skip option and its argument
+ ;;
+ -*)
+ # skip all other options
+ ;;
+ *)
+ [ -z "$module" ] && module=${words[i]}
+ ;;
+ esac
+ done
+
+ case $mode in
+ remove)
+ _installed_modules "$cur"
+ ;;
+ list)
+ # no completion available
+ ;;
+ file)
+ _filedir
+ ;;
+ insert)
+ # do filename completion if we're giving a path to a module
+ if [[ "$cur" == @(*/|[.~])* ]]; then
+ _filedir '@(?(k)o?(.gz))'
+ elif [[ -n "$module" ]]; then
+ # do module parameter completion
+ COMPREPLY=( $( compgen -W "$( /sbin/modinfo -p "$module" \
+ 2>/dev/null | cut -d: -f1 )" -- "$cur" ) )
+ else
+ _modules $version
+ fi
+ ;;
+ esac
+} &&
+complete -F _modprobe modprobe
+
+# ex: ts=4 sw=4 et filetype=sh
diff --git a/test/completion/modinfo.exp b/test/completion/modinfo.exp
new file mode 100644
index 0000000..8838454
--- /dev/null
+++ b/test/completion/modinfo.exp
@@ -0,0 +1 @@
+assert_source_completions modinfo
diff --git a/test/completion/modprobe.exp b/test/completion/modprobe.exp
new file mode 100644
index 0000000..405ca8e
--- /dev/null
+++ b/test/completion/modprobe.exp
@@ -0,0 +1 @@
+assert_source_completions modprobe
diff --git a/test/lib/completions/insmod.exp b/test/lib/completions/insmod.exp
index a312c89..ca7c30f 100644
--- a/test/lib/completions/insmod.exp
+++ b/test/lib/completions/insmod.exp
@@ -11,7 +11,7 @@ proc teardown {} {
setup
-assert_complete_any "insmod in"
+assert_complete_any "insmod "
sync_after_int
diff --git a/test/lib/completions/modinfo.exp b/test/lib/completions/modinfo.exp
new file mode 100644
index 0000000..2f6e413
--- /dev/null
+++ b/test/lib/completions/modinfo.exp
@@ -0,0 +1,35 @@
+proc setup {} {
+ save_env
+}
+
+
+proc teardown {} {
+ assert_env_unmodified
+}
+
+
+setup
+
+
+set test "in<TAB> should complete modulename"
+assert_complete_any "modinfo in" $test
+
+
+sync_after_int
+
+
+set test "should not complete anything for non-existent kernel"
+assert_no_complete "modinfo -k you-dont-have-such-kernel in" $test
+
+
+sync_after_int
+
+
+set test "should complete filepaths"
+assert_complete "/lib/" "modinfo /li" $test -nospace
+
+
+sync_after_int
+
+
+teardown
diff --git a/test/lib/completions/modprobe.exp b/test/lib/completions/modprobe.exp
new file mode 100644
index 0000000..5391d4a
--- /dev/null
+++ b/test/lib/completions/modprobe.exp
@@ -0,0 +1,49 @@
+proc setup {} {
+ save_env
+}
+
+
+proc teardown {} {
+ assert_env_unmodified
+}
+
+
+setup
+
+
+set test "--remov<TAB> should complete \"--remove\""
+assert_complete "--remove" "modprobe --remov" $test
+
+
+sync_after_int
+
+
+set test "in<TAB> should complete modulename"
+assert_complete_any "modprobe in" $test
+
+
+sync_after_int
+
+
+set test "should not complete anything for non-existent kernel"
+assert_no_complete "modprobe -S you-dont-have-such-kernel in" $test
+
+
+sync_after_int
+
+
+set test "should not complete anything for non-existent module"
+assert_no_complete "modprobe you-dont-have-such-module " $test
+
+
+sync_after_int
+
+
+set test "should complete filepaths"
+assert_complete "/lib/" "modprobe /li" $test -nospace
+
+
+sync_after_int
+
+
+teardown
--
bash-completion
More information about the Bash-completion-commits
mailing list