[Bash-completion-devel] Bug#733815: Modules completion takes a very long time

Linda Walsh bash at tlinx.org
Wed Jan 1 00:09:01 UTC 2014


This is related to this bug, but more, this bug reminded me.

I wrote a completion routine for 'modprobe' that, in the module list,
only shows you the modules you have not loaded yet.

I know it is _possible_ to load an already-loaded module, again, but
in my own use, that's usually not the case -- I usually compile a bunch
of optional modules that I might 'conceivably', want to try out and in
looking through modules to find out what they are/do, I find it useful
to have modprobe default to listing only modules that are NOT loaded
yet.


Is this something others would find useful?

I only wrote completion for modprobe and the only thing I focused
on were having it list the modules in my kernel that were not loaded.

I can't say how long it would take to complete on debian following
a bunch of symlinks, but on my system, it takes about a tenth of a second
to come up with a list of 376 possible modules on my system, so unless
there is something odd about the list on debian, it might be faster..?

Anyway, it would be interesting to know if this solves the slowness problem
with all the symlinks...

(obviously one would need to source this file):
----------------------------------------------

#!/bin/bash

function _clean_n_sort_mods {
   declare -a mods
   readarray mods < <(echo "$(find /lib/modules/$(uname -r) -name \*.ko)")
   mods=("${mods[@]##*/}")
   echo "${mods[@]//.ko/}"
}

function _loaded_mods {
   lsmod |tail --lines=+2|sed -r 's/ .*$//'
}

function _newmods {
   declare cur prev words cword
   _get_comp_words_by_ref cur
   declare -a ldm ld1 ld2 ldup unloaded replies
   readarray ldm< <(_loaded_mods)
   #spacey kernel-hacker special; for those forgetting '-' != '_ui
   readarray ld1< <(echo "${ldm[@]//_/-}" "${ldm[@]//-/_}")
   readarray ldup< <(echo "${ld1[@]}" "${ld1[@]}" "${ld2[@]}" "${ld2[@]}")
   readarray unloaded< <(_clean_n_sort_mods)
   readarray lines< <(echo "${ldup[@]}" "${unloaded[@]}")
   readarray -t replies< <(echo "${lines[@]}"|tr -d " "|grep -Pv 
'^\s*$'|sort|uniq -u)

   COMPREPLY=( $(compgen -W "$(echo "${replies[@]}")" -- "$cur" ) )
}

complete -F _newmods modprobe
#------------------------------------------------------------------------------



More information about the Bash-completion-devel mailing list