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

PATCH: completions for su and implicit fg/bg



First, is a patch to _first which completes jobs after an initial % on
the command line. This is useful when foregrounding or backgrounding a
process without fg/bg. This feature seems to be undocumented actually.
I'll send a patch to the docs unless someone locates it there somewhere
already. Completion of commands where the command will be run should
really quote an initial '%' (or more to the point should preserve a
quote which has been typed). This wouldn't be that easy to do though
because in many other cases when completing command names, an initial
'%' would be totally valid.

The second new completion is for su. Usernames are completed as the
first parameter or second after a -. Next it works out which shell the
specified user has and completes options for that shell. My first
thought was that I'd use something like compgen -l $shell but ofcourse
compgen doesn't support -l. Judging by _find, it seems that _normal is
the way to do this but it would need the shell's name to be on the
command-line. I've got it to work by pulling the relevant parts out of
_normal and roughly repeating it. I didn't bother with the pattern
matching stuff though. A better way would be if _normal took an optional
parameter similar to the parameter to compctl -l. I can make this change
if it is agreed. So that this stuff for completing shell parameters
after su is actually useful, I've included a basic completion for the
common shells which just does the -c option. Note that I've not bothered
to deal with the extra options which GNU su offers because I think they
are all utterly pointless.

Oliver Kiddle

*** Completion/Base/_first.old	Mon Jun 21 08:14:44 1999
--- Completion/Base/_first	Fri Jul  9 10:03:52 1999
***************
*** 61,63 ****
--- 61,68 ----
  #         (( i++ ))
  #       done
  #     fi
+ 
+ # Complete jobs in implicit fg and bg
+ if [[ "$CURRENT" = 1 && "$PREFIX[1]" = "%" ]]; then
+   compgen -j -P '%'
+ fi
*** Completion/User/_su.old	Fri Jul  9 10:25:55 1999
--- Completion/User/_su	Fri Jul  9 10:25:20 1999
***************
*** 0 ****
--- 1,22 ----
+ #compdef su
+ 
+ local shell comp name usr base
+ 
+ [[ $words[2] != - ]]
+ (( base=$?+2 ))
+ 
+ if [[ CURRENT -eq base ]]; then
+   compgen -u && return
+   usr=root
+ elif [[ CURRENT -ge base+1 ]]; then
+   usr=$words[base]
+ else
+   return
+ fi
+ 
+ shell=${"$(egrep "^$usr:" </etc/passwd)"##*:}
+ compset -n $base
+ for name in $shell $shell:t -default-; do
+   comp="$_comps[$name]"
+   [[ ! -z "$comp" ]] && "$comp" && return
+ done  
*** Completion/User/_sh.old	Fri Jul  9 10:25:52 1999
--- Completion/User/_sh	Fri Jul  9 10:25:20 1999
***************
*** 0 ****
--- 1,3 ----
+ #compdef sh ksh bash zsh csh tcsh rc
+ 
+ compset -N '-c' && _normal



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