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

Re: functions/Completion/Linux/_modutils



On May 14,  6:16pm, sergio wrote:
}
} sudo modprobe <TAB> should list all available modules (may be all not
} loaded modules) but it doesn't.

Aha.  So the problem is with the completion for sudo, not the completion
for modprobe.  Calling "_normal" is not adequate when the environment in
which the command will run is not the same as the environment in which
the completer is running.

I can't advocate breaking _modutils (and everything else, one at a time)
for all ordinary cases, just to fix this for "sudo".  So how about this?

% zstyle :complete:sudo: environ \
    PATH="/sbin:/usr/sbin:$PATH" HOME="/root"
% sudo modprobe <TAB>

The environ style is an array of VAR=value which are exported into the
local environment before the completion for the target command is
invoked.  If this looks OK and nobody beats me to it, I'll add some
documentation, too.

Of course it would be preferable if "sudo -H /tmp/foo" would export
HOME=/tmp/foo, and if the style could be specialized to the target
user for "sudo -u" and so on, but I'm not prepared to go that far
overboard just now.

Index: Completion/Unix/Command/_sudo
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-4.0/Completion/Unix/Command/_sudo,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 _sudo
--- zsh-4.3/Completion/Unix/Command/_sudo	9 Apr 2001 20:14:09 -0000	1.1.1.1
+++ _sudo	14 May 2008 15:22:23 -0000
@@ -1,5 +1,12 @@
 #compdef sudo
 
+local curcontext="$curcontext" environ e
+zstyle -a "$curcontext" environ environ
+
+for e in "${environ[@]}"
+do local -x "$e"
+done
+
 _arguments \
        '-V[show version]' \
        '-l[list allowed commands]' \



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