zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@zanshin.com>
To: Wayne Davison <wayne@clari.net>
Cc: Sweth Chandramouli <sweth@astaroth.nit.gwu.edu>,
	ZSH Users <zsh-users@sunsite.auc.dk>
Subject: Re: making sudo work with functions/builtins
Date: Tue, 16 Feb 1999 21:30:03 -0800 (PST)	[thread overview]
Message-ID: <14026.21467.871243.164811@tiny.zanshin.com> (raw)
In-Reply-To: <199902162241.OAA11943@bebop.clari.net>

Wayne Davison writes:
 > Sweth Chandramouli writes:
 > > i just had a little brainstorm about how to get around this:
 > > 
 > > % alias sudo='sudo cmd '
 > > % cat cmd
 > > #!/bin/sh
 > > eval $SHELL -c \"$@\"
 > 
 > While this cures the error of sudo trying to run "nocorrect", it
 > does not propagate the "nocorrect" forward soon enough to turn off
 > spelling corrections on the command.  This delayed application is
 > more of a problem with a command that has the "noglob" modifier:
 > 
 > % alias e='noglob echo'
 > % e f*
 > f*
 > % sudo e f*
 > foo
 > 
 > I know of no way around this problem.

Aw, sure you do.  You almost got it ... all you have to do is reverse
the order of handling noglob.

do_sudo() { 
    integer glob=1
    while (($#))
    do
        case $1 in
        command|exec|-) shift; break;;
	nocorrect) shift; continue;;
	noglob) glob=0; shift; continue;;
	*) break;;
	esac
    done
    (($# == 0)) && 1=zsh
    if ((glob))
    then
        command sudo $~==*
    else
	command sudo $==*
    fi
}
alias sudo='noglob do_sudo '

However, I don't know of any equivalent way to handle nocorrect.

 > It doesn't allow me to run any shell builtins or functions, though.

I don't have 3.1.5 on this laptop, so I forget the new "whence" option
for this, but I think you could test whether something was a builtin
or function, and if so cause the do_sudo or my_sudo helper function to
invoke zsh -c in such a way as to run it.

I'm not sure what builtins it would be useful to run that way, but ...


      reply	other threads:[~1999-02-17 17:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-02-16  0:15 Sweth Chandramouli
1999-02-16 22:41 ` Wayne Davison
1999-02-17  5:30   ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=14026.21467.871243.164811@tiny.zanshin.com \
    --to=schaefer@zanshin.com \
    --cc=schaefer@brasslantern.com \
    --cc=sweth@astaroth.nit.gwu.edu \
    --cc=wayne@clari.net \
    --cc=zsh-users@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).