zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: rmmod/modprobe -r completion
@ 2001-05-15  2:26 Clint Adams
  2001-05-15 15:07 ` Oliver Kiddle
  0 siblings, 1 reply; 4+ messages in thread
From: Clint Adams @ 2001-05-15  2:26 UTC (permalink / raw)
  To: zsh-workers

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.

Index: Completion/Unix/Command/.distfiles
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/.distfiles,v
retrieving revision 1.4
diff -u -r1.4 .distfiles
--- Completion/Unix/Command/.distfiles	2001/05/03 13:05:49	1.4
+++ Completion/Unix/Command/.distfiles	2001/05/15 02:17:10
@@ -14,5 +14,5 @@
 _dd           _gprof        _lynx         _perldoc      _telnet       _pine
 _dict         _grep         _lzop         _prcs         _tiff         _elm
 _diff         _gs           _make         _psutils      _tin	_apm  _mail
-_loadkeys
+_loadkeys     _modutils
 '
Index: Completion/Unix/Command/_modutils
===================================================================
RCS file: _modutils
diff -N _modutils
--- /dev/null	Mon Dec 11 17:26:27 2000
+++ _modutils	Mon May 14 19:17:10 2001
@@ -0,0 +1,44 @@
+#compdef modprobe rmmod
+
+local loaded
+
+_modutils_loaded_modules() {
+
+if [[ -f /proc/modules ]]; then
+ loaded=(${${(f)"$(</proc/modules)"}%% *})
+elif [[ -x /sbin/lsmod ]]; then
+ loaded=(${${${(f)"$(</sbin/lsmod)"}%% *}%Module})
+else
+ return 1
+fi
+
+compadd -a loaded
+return 0
+}
+
+case "$service" in
+  rmmod)
+
+  _arguments '(--all)-a[remove all unused autocleanable modules]' \
+             '(-a)--all' \
+             '(--persist)-e[save persistent data]' \
+             '(-e)--persist' \
+             '(--help)-h[print help text]' \
+             '(-h)--help' \
+             '(--stacks)-r[remove a module stack]' \
+             '(-r)--stacks' \
+             '(--syslog)-s[output to syslog]' \
+             '(-s)--syslog' \
+             '(--verbose)-v[be verbose]' \
+             '(-v)--verbose' \
+             '(--version)-V[print version]' \
+             '(-V)--version' \
+             '*:loaded module:_modutils_loaded_modules'
+  ;;
+
+  modprobe)
+  _arguments '(--remove)-r[remove]:loaded module:_modutils_loaded_modules' \
+             '(-r)--remove:loaded module:_modutils_loaded_modules'
+  ;;
+
+esac


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: rmmod/modprobe -r completion
  2001-05-15  2:26 PATCH: rmmod/modprobe -r completion Clint Adams
@ 2001-05-15 15:07 ` Oliver Kiddle
  2001-05-16 12:00   ` Clint Adams
  0 siblings, 1 reply; 4+ messages in thread
From: Oliver Kiddle @ 2001-05-15 15:07 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: rmmod/modprobe -r completion
  2001-05-15 15:07 ` Oliver Kiddle
@ 2001-05-16 12:00   ` Clint Adams
  2001-05-16 12:32     ` Clint Adams
  0 siblings, 1 reply; 4+ messages in thread
From: Clint Adams @ 2001-05-16 12:00 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: zsh-workers

> 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?

Well, modprobe could benefit from the use of states, so here's
modprobe supporting a few more options:


Index: Completion/Unix/Command/_modutils
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_modutils,v
retrieving revision 1.2
diff -u -r1.2 _modutils
--- Completion/Unix/Command/_modutils	2001/05/15 15:14:21	1.2
+++ Completion/Unix/Command/_modutils	2001/05/16 11:59:02
@@ -32,12 +32,37 @@
              '(-v)--verbose' \
              '(--version)-V[print version]' \
              '(-V)--version' \
-             '*:loaded module:_modutils_loaded_modules'
+             '*:loaded module:_modutils_loaded_modules' && return 0
   ;;
 
   modprobe)
-  _arguments '(--remove)-r[remove]:loaded module:_modutils_loaded_modules' \
-             '(-r)--remove:loaded module:_modutils_loaded_modules'
+
+  _modprobe_arguments=(
+             '(--all)-a[all]' \
+             '(-a)--all' \
+             '(--showconfig)-c[showconfig]' \
+             '(-c)--showconfig' \
+             '(--debug)-d[debug]' \
+             '(-d)--debug' \
+             '(--autoclean)-k[set autoclean]' \
+             '(-k)--autoclean' \
+             '(--show)-n[do not act]' \
+             '(-n)--show'
+  )
+
+  _arguments '(--remove)-r[remove]:*:loaded module:->modprobe_remove' \
+             '(-r)--remove:*:loaded module:->modprobe_remove' \
+	     "$_modprobe_arguments[@]" && return 0
+
+  ;;
+
+esac 
+
+case "$state" in
+  modprobe_remove)
+        _call_function ret _modutils_$state && return ret
+        _arguments "$_modprobe_arguments[@]" \
+                   '*:loaded module:_modutils_loaded_modules'
   ;;
 
 esac


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: rmmod/modprobe -r completion
  2001-05-16 12:00   ` Clint Adams
@ 2001-05-16 12:32     ` Clint Adams
  0 siblings, 0 replies; 4+ messages in thread
From: Clint Adams @ 2001-05-16 12:32 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: zsh-workers

> Well, modprobe could benefit from the use of states, so here's
> modprobe supporting a few more options:

And here's some more.


Index: Completion/Unix/Command/_modutils
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_modutils,v
retrieving revision 1.3
diff -u -r1.3 _modutils
--- Completion/Unix/Command/_modutils	2001/05/16 12:02:17	1.3
+++ Completion/Unix/Command/_modutils	2001/05/16 12:30:41
@@ -47,11 +47,25 @@
              '(--autoclean)-k[set autoclean]' \
              '(-k)--autoclean' \
              '(--show)-n[do not act]' \
-             '(-n)--show'
+             '(-n)--show' \
+             '(--quiet)-q[do not complain about insmod failures]' \
+             '(-q)--quiet' \
+             '(--syslog)-s[report via syslog instead of stderr]' \
+             '(-s)--syslog' \
+             '(--type)-t[module type]:moduletype:' \
+             '(-t)--type:moduletype:' \
+             '(--verbose)-v[print all commands as executed]' \
+             '(-v)--verbose' \
+             '(--version)-V[show release version]' \
+             '(-V)--version' \
+             '(--config)-C[config file]:config file:_files' \
+             '(-C)--config:config file:_files'
   )
 
   _arguments '(--remove)-r[remove]:*:loaded module:->modprobe_remove' \
              '(-r)--remove:*:loaded module:->modprobe_remove' \
+             '(--list)-l[list matching modules]:*:module file:->modprobe_list' \
+             '(-l)--list:*:module file:->modprobe_list' \
 	     "$_modprobe_arguments[@]" && return 0
 
   ;;
@@ -64,5 +78,10 @@
         _arguments "$_modprobe_arguments[@]" \
                    '*:loaded module:_modutils_loaded_modules'
   ;;
+
+  modprobe_list)
+        _call_function ret _modutils_$state && return ret
+        _arguments "$_modprobe_arguments[@]" \
+                   '*:module file:compadd ${^${(M)${(f)"$(modprobe -c)"}:#path*}#*[=]}/**/*.o(:t)'
 
 esac


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-05-16 12:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-15  2:26 PATCH: rmmod/modprobe -r completion Clint Adams
2001-05-15 15:07 ` Oliver Kiddle
2001-05-16 12:00   ` Clint Adams
2001-05-16 12:32     ` Clint Adams

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).