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

Re: Command alias in non-command position

"Andrej Borsenkow" <borsenkow.msk@xxxxxx> writes:

> I have some often used aliases, e.g. 
> vi=elvis
> view='elvis -R'
> etc
> Unfortunately, if I try to do e.g.
> sudo vi ...
> The /usr/bin/vi is started instead of elvis.
> Is there any easy way to use my lovely aliases in this case?

An obvious immediate approach would be to use global aliases:

	alias -g vi=elvis

Then vi will expand to elvis in lots of places, so "sudo vi" will run
elvis.  But "echo vi" will also print elvis, so perhaps this is too
pervasive.  Could I define sudo somehow, to say that its first
argument ought to be expanded as if it were in the command position?
(As a function, maybe?)

Is this a case for configurable expansion?  (I already think I ought
to be able to change how spell-correction works, to say that some
words just don't correspond to files (like the first argument to tar),
and possibly to say that some words ought to correspond to
non-existent files.  This feels like a related feature.)

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