zsh-workers
 help / color / mirror / code / Atom feed
* Next improve of completion of modprobe module parameters
@ 2008-09-26 22:35 Jörg Sommer
  2008-09-27  2:06 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Jörg Sommer @ 2008-09-26 22:35 UTC (permalink / raw)
  To: zsh-workers

Hi,

maybe, someone has a better idea how to remove the elements of
loaded_modules from modules in the second patch. Or can someone explain
this:

% a=12\|4
% b=( {10..15} )
% echo ${b:#($a)}
10 11 12 13 14 15
% eval "echo \${b:#($a)}"
10 11 13 14 15

Why doesn't the non‐eval version work?

commit 1afe1e700c8a205790fcd57cf50abae8fa176d15
Author: Jörg Sommer <joerg@alea.gnuu.de>
Date:   Fri Sep 26 20:55:02 2008 +0200

    Restrict names of modules files to *.ko

diff --git a/Completion/Linux/Command/_modutils b/Completion/Linux/Command/_modutils
index f422fac..378c2d5 100644
--- a/Completion/Linux/Command/_modutils
+++ b/Completion/Linux/Command/_modutils
@@ -78,7 +78,7 @@ case "$state" in
     modules=( ${${${${(f)"$(_call_program modules ${(M)words[1]##*/}modprobe -l 2>/dev/null)"}:#}##*/}%%.*} )
     _tags files modules
     while _tags; do
-      _requested files expl "module file"  _files && ret=0
+      _requested files expl "module file"  _files -g '*.ko' && ret=0
       _requested modules expl module compadd -a modules && ret=0
     done
   ;;

commit a9e52391259d3daf77b0fb74e9eb9bbd09e4ed1a
Author: Jörg Sommer <joerg@alea.gnuu.de>
Date:   Fri Sep 26 20:56:43 2008 +0200

    Print only non‐loaded modules as modprobe completion

diff --git a/Completion/Linux/Command/_modutils b/Completion/Linux/Command/_modutils
index 378c2d5..7c6c666 100644
--- a/Completion/Linux/Command/_modutils
+++ b/Completion/Linux/Command/_modutils
@@ -38,7 +38,7 @@ case "$service" in
       '(-C --config)'{-C,--config}'[specify config file]:config file:_files' \
       "(-r --remove -l --list -t --type -a --all $ign)"{-r,--remove}'[remove module (stacks)]' \
       "(* -l --list -r --remove $ign)"{-l,--list}'[list matching modules]' \
-      "(-c $ign)1:modules:->all_modules" \
+      "(-c $ign)1:modules:->loadable_modules" \
       "(-c -l --list -t --type $ign)*:params:->params" && ret=0
       
       [[ -n $state ]] && (( $+opt_args[-r] )) && state=loaded_modules        
@@ -62,20 +62,28 @@ case "$service" in
 esac 
 
 case "$state" in
-  loaded_modules)
+  loaded_modules|loadable_modules)
     if [[ -r /proc/modules ]]; then
-     modules=(${${(f)"$(</proc/modules)"}%% *})
+     loaded_modules=(${${(f)"$(</proc/modules)"}%% *})
     elif [[ -x /sbin/lsmod ]]; then
-     modules=(${${(f)"$(/sbin/lsmod)"}[2,-1]%% *})
+     loaded_modules=(${${(f)"$(/sbin/lsmod)"}[2,-1]%% *})
     else
      return 1
     fi
-    
-    _wanted modules expl 'loaded module' compadd -a modules && return
-  ;;
+
+    if [[ $state = loaded_modules ]]; then
+        _wanted modules expl 'loaded module' compadd -a loaded_modules && return
+        return ret
+    fi
+  ;&
 
   all_modules)
     modules=( ${${${${(f)"$(_call_program modules ${(M)words[1]##*/}modprobe -l 2>/dev/null)"}:#}##*/}%%.*} )
+
+    if [[ $state = loadable_modules ]]; then
+        eval "modules=( \${modules:#(${(j:|:)${=loaded_modules//_/-}})} )"
+    fi
+
     _tags files modules
     while _tags; do
       _requested files expl "module file"  _files -g '*.ko' && ret=0

Bye, Jörg
-- 
"The future is here. It's just not widely distributed yet."
                                       (William Gibson)


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

* Re: Next improve of completion of modprobe module parameters
  2008-09-26 22:35 Next improve of completion of modprobe module parameters Jörg Sommer
@ 2008-09-27  2:06 ` Bart Schaefer
  2008-09-27 20:56   ` Jörg Sommer
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2008-09-27  2:06 UTC (permalink / raw)
  To: zsh-workers

On Sep 26, 10:35pm, joerg@alea.gnuu.de wrote:
}
} % a=12\|4
} % b=( {10..15} )
} % echo ${b:#($a)}
} 10 11 12 13 14 15
} % eval "echo \${b:#($a)}"
} 10 11 13 14 15
} 
} Why doesn't the non-eval version work?

echo ${b:#($~a)}

The "|" in $a is implicitly quoted unless you use $~a.


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

* Re: Next improve of completion of modprobe module parameters
  2008-09-27  2:06 ` Bart Schaefer
@ 2008-09-27 20:56   ` Jörg Sommer
  0 siblings, 0 replies; 3+ messages in thread
From: Jörg Sommer @ 2008-09-27 20:56 UTC (permalink / raw)
  To: zsh-workers

Hello Bart,

Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Sep 26, 10:35pm, joerg@alea.gnuu.de wrote:
>}
>} % a=12\|4
>} % b=( {10..15} )
>} % echo ${b:#($a)}
>} 10 11 12 13 14 15
>} % eval "echo \${b:#($a)}"
>} 10 11 13 14 15
>} 
>} Why doesn't the non-eval version work?
>
> echo ${b:#($~a)}
>
> The "|" in $a is implicitly quoted unless you use $~a.

Thanks for the enlightenment. This is a better version of the patch:

commit b715bc93beb7c39297435926c17a18178e6e50aa
Author: Jörg Sommer <joerg@alea.gnuu.de>
Date:   Fri Sep 26 20:56:43 2008 +0200

    Print only non‐loaded modules as modprobe completion

diff --git a/Completion/Linux/Command/_modutils b/Completion/Linux/Command/_modutils
index 378c2d5..06e9b14 100644
--- a/Completion/Linux/Command/_modutils
+++ b/Completion/Linux/Command/_modutils
@@ -38,7 +38,7 @@ case "$service" in
       '(-C --config)'{-C,--config}'[specify config file]:config file:_files' \
       "(-r --remove -l --list -t --type -a --all $ign)"{-r,--remove}'[remove module (stacks)]' \
       "(* -l --list -r --remove $ign)"{-l,--list}'[list matching modules]' \
-      "(-c $ign)1:modules:->all_modules" \
+      "(-c $ign)1:modules:->loadable_modules" \
       "(-c -l --list -t --type $ign)*:params:->params" && ret=0
       
       [[ -n $state ]] && (( $+opt_args[-r] )) && state=loaded_modules        
@@ -62,20 +62,28 @@ case "$service" in
 esac 
 
 case "$state" in
-  loaded_modules)
+  loaded_modules|loadable_modules)
     if [[ -r /proc/modules ]]; then
-     modules=(${${(f)"$(</proc/modules)"}%% *})
+     loaded_modules=(${${(f)"$(</proc/modules)"}%% *})
     elif [[ -x /sbin/lsmod ]]; then
-     modules=(${${(f)"$(/sbin/lsmod)"}[2,-1]%% *})
+     loaded_modules=(${${(f)"$(/sbin/lsmod)"}[2,-1]%% *})
     else
      return 1
     fi
-    
-    _wanted modules expl 'loaded module' compadd -a modules && return
-  ;;
+
+    if [[ $state = loaded_modules ]]; then
+        _wanted modules expl 'loaded module' compadd -a loaded_modules && return
+        return ret
+    fi
+  ;&
 
   all_modules)
     modules=( ${${${${(f)"$(_call_program modules ${(M)words[1]##*/}modprobe -l 2>/dev/null)"}:#}##*/}%%.*} )
+
+    if [[ $state = loadable_modules ]]; then
+        modules=( ${modules:#(${(j:|:)~${loaded_modules//_/-}})} )
+    fi
+
     _tags files modules
     while _tags; do
       _requested files expl "module file"  _files -g '*.ko' && ret=0

Bye, Jörg.
-- 
Objektivität ist die Wahnvorstellung, Beobachtungen könnten ohne
Beobachter gemacht werden – Heinz v. Foerster


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

end of thread, other threads:[~2008-09-27 22:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-26 22:35 Next improve of completion of modprobe module parameters Jörg Sommer
2008-09-27  2:06 ` Bart Schaefer
2008-09-27 20:56   ` Jörg Sommer

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).