From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28355 invoked from network); 17 Mar 1999 09:22:42 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 17 Mar 1999 09:22:42 -0000 Received: (qmail 261 invoked by alias); 17 Mar 1999 09:14:48 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 5836 Received: (qmail 232 invoked from network); 17 Mar 1999 09:14:46 -0000 From: "Andrej Borsenkow" To: "ZSH workers mailing list" Subject: sudo completion Date: Tue, 16 Mar 1999 20:06:26 +0300 Message-ID: <003901be6fcf$53d31b50$21c9ca95@mowp.siemens.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 As I quite often use sudo, I really like to have it. May be, it will be of some use to others. Just a comment - there is no way for sudo to run internal (builtin) command, so, I explicitly complete only external commands if we are in command position. cheers /andrej P.S. I don't provide a it as a patch as I don't deem it good enough. It works for me though ... #defcomp sudo emulate -RL zsh ## ## Get the position of the first non-option argument (it should be command) ## The $words[1] is always "sudo" ## local -i i=1 cmd=0 while [[ $i -lt $#words ]] do case $words[++i] in -? ) continue ;; * ) if [[ $i -gt 2 && ($words[i-1] == -p || $words[i-1] == -u) ]] then continue fi cmd=$i break ;; esac done ## ## If we are at the first non-option argument, simply complete it ## as if it were external command ## If we are after the first non-option argument, complete ## as if it were given command ## Else the only sesnible completion seems to be for -u (users) ## if [[ $cmd -gt 0 && -position cmd ]] then compgen -m elif [[ $cmd -gt 0 && -position cmd -1 ]] _normal elif [[ -current -1 -u ]] then compgen -u else return 0 fi