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

auil at usp.br auil at usp.br
Wed Jan 1 18:17:42 UTC 2014


> Another issue is that some filenames have '-' in them, but the module 
> names have '_' in them. 

This is a problem because the modules filenames are a mess. Some 
filenames have an underscore '_' too. 

> Does the current solution filter out 
> duplicates due to the modulename and filename not being the same 
> (i.e. '-' vs. '_')? 

If you want to get 

(all available mods) minus (already loaded mods) 

a solution is to change hyphen '-' to underscore '_' in the filenames, 
but not the opposite. This is because the output of "lsmod" or 
"/proc/modules" is always with underscore. 

I try this modification (and renaming) of you functions 

--------------------------------------- 
function _sort_all_mods { 
find /lib/modules/$(uname -r) -type f -name \*.ko|sed 's|.*/||g;s|[.]ko$||'|sort -u|tr - _ 
} 

function _loaded_mods_regexp { 
local a 
a=$(awk '{print $1}' /proc/modules|sort -u|sed 's/^/^/;s/$/$/'|tr "\n" '|') 
echo ${a%|} 
} 

function _newmods { 
declare cur prev words cword 
_get_comp_words_by_ref cur 
COMPREPLY=( $(compgen -W "$(_sort_all_mods|grep -E -v "$(_loaded_mods_regexp)")" -- "$cur" ) ) 
} 

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

Using the functions above I get the right filtering 

$ _sort_all_mods | wc -l 
2542 

$ _loaded_mods_regexp | tr '|' "\n" | wc -l 
79 

$ _sort_all_mods | grep -E -v "$(_loaded_mods_regexp)" | wc -l 
2463 

$ echo 2542 - 79 | bc 
2463 

> So sounds like using a modified function based on the function 
> I used and your optimizations would "ignore" the problem of the 
> extra links? 

Your solution works because uses command "find", which ignore links 
by default. I mean, "find" is equivalent to "find -P". 

Regards, 

FA 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/bash-completion-devel/attachments/20140101/06fb613a/attachment-0001.html>


More information about the Bash-completion-devel mailing list