--- bash-completion-1.3.orig/completions/module-init-tools 2011-01-21 10:36:11.000000000 +0100 +++ bash-completion-1.3/completions/module-init-tools 2011-05-03 18:57:22.617585290 +0200 @@ -20,37 +20,175 @@ # list of all available modules for the version of the kernel currently # running. # -have insmod || have modprobe || have modinfo && +have insmod && _insmod() { - local cur prev modpath + local cur prev COMPREPLY=() _get_comp_words_by_ref cur prev - # behave like lsmod for modprobe -r - if [[ ${1##*/} == modprobe && "${COMP_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 _filedir '@(?(k)o?(.gz))' return 0 fi - if [[ $COMP_CWORD -gt 1 && "${COMP_WORDS[COMP_CWORD-1]}" != -* ]]; then - # do module parameter completion - COMPREPLY=( $( compgen -W "$( /sbin/modinfo -p ${COMP_WORDS[1]} | \ - cut -d: -f1 )" -- "$cur" ) ) + if [[ $COMP_CWORD -gt 1 ]]; then + # do module parameter completion, ignore modinfo errors + COMPREPLY=( $( compgen -W "$( /sbin/modinfo -p ${COMP_WORDS[1]} \ + 2>/dev/null | cut -d: -f1 )" -- "$cur" ) ) else _modules $(uname -r) fi return 0 } && -complete -F _insmod insmod modprobe modinfo +complete -F _insmod insmod + +have modprobe && +_modprobe() +{ + # @todo arguments completion is incomplete ~Lekensteyn lekensteyn@gmail.com + local cur prev mode opts module + opts='-r -v -n -i --remove --verbose --dry-run --ignore-install \ +--ignore-remove -l -t -a --list --type --all' + + COMPREPLY=() + _get_comp_words_by_ref cur prev + + for (( i=1; i < ${#COMP_WORDS[@]}-1; i++ )); do + case ${COMP_WORDS[$i]]} in + -r|--remove) + # loaded module completion + mode=remove + ;; + -l|--list) + mode=list + ;; + -c|--showconfig) + # no completion + return 0 + ;; + --dump-modversions) + # filename completion + mode=file + ;; + -*) + # catch all options like -x and --xxx + ;; + *) + [ -z "$module" ] && module=${COMP_WORDS[$i]} + ;; + esac + done + + case "$prev" in + -C|--config) + _filedir + return 0 + ;; + -t|--type) + _filedir -d + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + case $mode in + remove) + opts='-r -v -n -i --remove --verbose --dry-run --ignore-install\ + --ignore-remove' + ;; + list) + opts='-l -t -a --list --type --all' + ;; + file) + opts='' + ;; + esac + [ -n "$opts" ] && COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) ) + return 0 + fi + + case $mode in + remove) + _installed_modules "$cur" + ;; + list) + # complete relative to /lib/modules/kernel-version/ + # todo... + ;; + file) + # complete to any file + _filedir + ;; + *) + # do filename completion if we're giving a path to a module + if [[ "$cur" == */* ]]; then + _filedir '@(?(k)o?(.gz))' + return 0 + fi + if [[ -n "$module" ]]; then + # do module parameter completion, ignoring modinfo errors + COMPREPLY=( $( compgen -W "$( /sbin/modinfo -p "$module" \ + 2>/dev/null | cut -d: -f1 )" -- "$cur" ) ) + else + _modules $(uname -r) + fi + ;; + esac + + return 0 +} && +complete -F _modprobe modprobe + +have modinfo && +_modinfo() +{ + local cur prev kernel="$(uname -r)" + + COMPREPLY=() + _get_comp_words_by_ref cur prev + + case "$prev" in + -F|--field) + # case-insensitive + COMPREPLY=( $( compgen -W 'author description license parm depends \ + alias filename srcversion vermagic staging version' -- "$(echo "$cur" | tr '[:upper:]' '[:lower:]')" ) ) + return 0 + ;; + -k) + _kernels + return 0 + ;; + esac + + # use this kernel function for completing modules + for (( i=1; i < ${#COMP_WORDS[@]}-2; i++ )); do + if [[ "${COMP_WORDS[$i]}" = "-k" ]]; then + kernel="${COMP_WORDS[$i+1]}" + fi + done + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W "-V -F -k -0 -a -d -l -p -n --version -field \ + --null" -- "$cur" ) ) + return 0 + fi + + # only show modules if the modules dir exists to prevent error messages + if [ -d "/lib/modules/$kernel" ]; then + if [[ "$cur" = */* ]]; then + _filedir + else + _modules "$kernel" + fi + fi + + return 0 +} && +complete -F _modinfo modinfo # Local variables: # mode: shell-script