Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: rmmod/modprobe -r completion



Clint Adams wrote:
> 
> This lacks all the other options to modprobe, and ignores
> insmod, but it seemed silly to just do rmmod and not have it work
> for modprobe -r.

This will be useful, cheers. 

> Index: Completion/Unix/Command/_modutils

This is probably the first thing which really could be in a Linux
directory. It's probably best to move it later once we have others
though.

> +if [[ -f /proc/modules ]]; then
> + loaded=(${${(f)"$(</proc/modules)"}%% *})
> +elif [[ -x /sbin/lsmod ]]; then
> + loaded=(${${${(f)"$(</sbin/lsmod)"}%% *}%Module})
                        ^
oops: you don't want to redirect in the /sbin/lsmod binary you want to
run it. I made a very similar mistake once when I tried to run a shell
script to fill out parameters to rm -rf - the result was not good.

> +compadd -a loaded
> +return 0

I also changed this to use _wanted so we get a description. I removed
the return statement because it should return 1 if the loaded array is
created but empty.

> +             '*:loaded module:_modutils_loaded_modules'

Hmm, this is fine but I'd have used a state or cached the loaded array
and passed it to _arguments. Which is more efficient - functions
declared in the autoloaded functions or states?

Oliver

Index: Completion/Unix/Command/_modutils
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_modutils,v
retrieving revision 1.1
diff -u -r1.1 _modutils
--- Completion/Unix/Command/_modutils   2001/05/15 02:32:53     1.1
+++ Completion/Unix/Command/_modutils   2001/05/15 15:01:39
@@ -1,19 +1,18 @@
 #compdef modprobe rmmod
 
-local loaded
+local expl loaded
 
 _modutils_loaded_modules() {
 
-if [[ -f /proc/modules ]]; then
+if [[ -r /proc/modules ]]; then
  loaded=(${${(f)"$(</proc/modules)"}%% *})
 elif [[ -x /sbin/lsmod ]]; then
- loaded=(${${${(f)"$(</sbin/lsmod)"}%% *}%Module})
+ loaded=(${${(f)"$(/sbin/lsmod)"}[2,-1]%% *})
 else
  return 1
 fi
 
-compadd -a loaded
-return 0
+_wanted modules expl 'loaded module' compadd -a loaded
 }
 
 case "$service" in



Messages sorted by: Reverse Date, Date, Thread, Author