From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18137 invoked from network); 9 Jul 1999 10:23:45 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 9 Jul 1999 10:23:45 -0000 Received: (qmail 11065 invoked by alias); 9 Jul 1999 10:23:37 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7067 Received: (qmail 11058 invoked from network); 9 Jul 1999 10:23:36 -0000 Message-ID: <3785CD8A.4CAA6484@thoth.u-net.com> Date: Fri, 09 Jul 1999 11:23:06 +0100 From: Oliver Kiddle X-Mailer: Mozilla 4.61 [en] (Win95; I) X-Accept-Language: en MIME-Version: 1.0 To: Zsh workers Subject: PATCH: completions for su and implicit fg/bg Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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:"