zsh-users
 help / color / mirror / code / Atom feed
* using command aliases with sudo
@ 2003-05-28  7:04 Eric Mangold
  2003-06-02  5:54 ` Borzenkov Andrey
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Eric Mangold @ 2003-05-28  7:04 UTC (permalink / raw)
  To: zsh-users

Hi,

I'm thinking of writing an extension to zsh that makes aliases work with sudo.

For example, I have an alias agi="apt-get install", since this needs root I 
often find myself typing "sudo agi foo", which of course doesn't work.

If someone has already done this or has suggestions for an implementation, 
please reply :)

-Eric


^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: using command aliases with sudo
  2003-05-28  7:04 using command aliases with sudo Eric Mangold
@ 2003-06-02  5:54 ` Borzenkov Andrey
  2003-06-02  6:24   ` Danek Duvall
  2003-06-02  6:23 ` Stephen Rueger
  2003-06-02  6:36 ` Wayne Davison
  2 siblings, 1 reply; 6+ messages in thread
From: Borzenkov Andrey @ 2003-06-02  5:54 UTC (permalink / raw)
  To: 'Eric Mangold', zsh-users

> Hi,
> 
> I'm thinking of writing an extension to zsh that makes aliases work with
> sudo.
> 
> For example, I have an alias agi="apt-get install", since this needs root
> I
> often find myself typing "sudo agi foo", which of course doesn't work.
> 
> If someone has already done this or has suggestions for an implementation,
> please reply :)
> 

One possible solution would be

sudo() {
	... add sudo options parsing here that sets sudo_options and
sudo_command...
	command sudo $sudo_options zsh -c "$sudo_command"
}

with obvious caveat that you have to modify sudoers to account for this. 

Extension to zsh makes no sense as sudo is started as external process that
you have no control of.

-andrey


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: using command aliases with sudo
  2003-05-28  7:04 using command aliases with sudo Eric Mangold
  2003-06-02  5:54 ` Borzenkov Andrey
@ 2003-06-02  6:23 ` Stephen Rueger
  2003-06-02  6:36 ` Wayne Davison
  2 siblings, 0 replies; 6+ messages in thread
From: Stephen Rueger @ 2003-06-02  6:23 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 470 bytes --]

On Wed, May 28, 2003 at 02:04:44AM -0500, Eric Mangold wrote:
> I'm thinking of writing an extension to zsh that makes aliases work
> with sudo.
> 
> For example, I have an alias agi="apt-get install", since this needs root I 
> often find myself typing "sudo agi foo", which of course doesn't work.
> 
> If someone has already done this or has suggestions for an implementation, 
> please reply :)

You can use a global alias (alias -g)

--
Stephen Rüger

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: using command aliases with sudo
  2003-06-02  5:54 ` Borzenkov Andrey
@ 2003-06-02  6:24   ` Danek Duvall
  2003-06-02  6:35     ` Borzenkov Andrey
  0 siblings, 1 reply; 6+ messages in thread
From: Danek Duvall @ 2003-06-02  6:24 UTC (permalink / raw)
  To: Borzenkov Andrey; +Cc: 'Eric Mangold', zsh-users

Andrey Borzenkov wrote:

> sudo() {
> 	... add sudo options parsing here that sets sudo_options and
> sudo_command...
> 	command sudo $sudo_options zsh -c "$sudo_command"
> }
> 
> with obvious caveat that you have to modify sudoers to account for this. 

What about

	if [[ -n $aliases[$sudo_command[1]] ]]; then
		sudo_command[1]=( $=aliases[$sudo_command[1]] )
	fi
	command sudo $sudo_options "$sudo_command"

Danek


^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: using command aliases with sudo
  2003-06-02  6:24   ` Danek Duvall
@ 2003-06-02  6:35     ` Borzenkov Andrey
  0 siblings, 0 replies; 6+ messages in thread
From: Borzenkov Andrey @ 2003-06-02  6:35 UTC (permalink / raw)
  To: 'Danek Duvall'; +Cc: 'Eric Mangold', zsh-users

> Andrey Borzenkov wrote:
> 
> > sudo() {
> > 	... add sudo options parsing here that sets sudo_options and
> > sudo_command...
> > 	command sudo $sudo_options zsh -c "$sudo_command"
> > }
> >
> > with obvious caveat that you have to modify sudoers to account for this.
> 
> What about
> 
> 	if [[ -n $aliases[$sudo_command[1]] ]]; then
> 		sudo_command[1]=( $=aliases[$sudo_command[1]] )
> 	fi
> 	command sudo $sudo_options "$sudo_command"
> 

excellent :)

-andrey


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: using command aliases with sudo
  2003-05-28  7:04 using command aliases with sudo Eric Mangold
  2003-06-02  5:54 ` Borzenkov Andrey
  2003-06-02  6:23 ` Stephen Rueger
@ 2003-06-02  6:36 ` Wayne Davison
  2 siblings, 0 replies; 6+ messages in thread
From: Wayne Davison @ 2003-06-02  6:36 UTC (permalink / raw)
  To: Eric Mangold; +Cc: zsh-users

On Wed, May 28, 2003 at 02:04:44AM -0500, Eric Mangold wrote:
> I'm thinking of writing an extension to zsh that makes aliases work with sudo.

You just need an alias with a trailing space, like this:

    alias sudo='command sudo '

That will cause zsh to expand your command aliases after a "sudo"
command.  Unfortunately, it's not perfect because it does not handle
sudo options properly.  I.e., this won't work (where "agi" is your
aliased command):

    sudo -u bin agi

but this will work:

    sudo agi

You can work around the problem for often-used users like this:

    alias sudobin='command sudo -u bin '

..wayne..


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-06-02  6:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-28  7:04 using command aliases with sudo Eric Mangold
2003-06-02  5:54 ` Borzenkov Andrey
2003-06-02  6:24   ` Danek Duvall
2003-06-02  6:35     ` Borzenkov Andrey
2003-06-02  6:23 ` Stephen Rueger
2003-06-02  6:36 ` Wayne Davison

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).