zsh-users
 help / color / mirror / code / Atom feed
* Command alias in non-command position
@ 1998-08-26 15:42 Andrej Borsenkow
  1998-08-26 16:35 ` Bruce Stephens
  0 siblings, 1 reply; 14+ messages in thread
From: Andrej Borsenkow @ 1998-08-26 15:42 UTC (permalink / raw)
  To: ZSH users mailing list

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?

thank you

/Andrej


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

* Re: Command alias in non-command position
  1998-08-26 15:42 Command alias in non-command position Andrej Borsenkow
@ 1998-08-26 16:35 ` Bruce Stephens
  1998-08-26 17:01   ` Zefram
  1998-08-26 17:36   ` Bart Schaefer
  0 siblings, 2 replies; 14+ messages in thread
From: Bruce Stephens @ 1998-08-26 16:35 UTC (permalink / raw)
  To: ZSH users mailing list

"Andrej Borsenkow" <borsenkow.msk@sni.de> 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.)


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

* Re: Command alias in non-command position
  1998-08-26 16:35 ` Bruce Stephens
@ 1998-08-26 17:01   ` Zefram
  1998-08-26 17:13     ` Bruce Stephens
  1998-08-26 17:36   ` Bart Schaefer
  1 sibling, 1 reply; 14+ messages in thread
From: Zefram @ 1998-08-26 17:01 UTC (permalink / raw)
  To: Bruce Stephens; +Cc: zsh-users

Bruce Stephens wrote:
>            Could I define sudo somehow, to say that its first
>argument ought to be expanded as if it were in the command position?

alias sudo='sudo '

permits alias expansion of the word following an alias-expanded sudo.

-zefram


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

* Re: Command alias in non-command position
  1998-08-26 17:01   ` Zefram
@ 1998-08-26 17:13     ` Bruce Stephens
  1998-08-26 17:26       ` Andrej Borsenkow
  1998-08-26 17:49       ` Bart Schaefer
  0 siblings, 2 replies; 14+ messages in thread
From: Bruce Stephens @ 1998-08-26 17:13 UTC (permalink / raw)
  To: zsh-users

"Zefram" <zefram@tao.co.uk> writes:

> alias sudo='sudo '
> 
> permits alias expansion of the word following an alias-expanded sudo.

Cool.  Presumably this works with

alias xargs='xargs '

too.  Now, what about find ... -exec?


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

* RE: Command alias in non-command position
  1998-08-26 17:13     ` Bruce Stephens
@ 1998-08-26 17:26       ` Andrej Borsenkow
  1998-08-26 17:49       ` Bart Schaefer
  1 sibling, 0 replies; 14+ messages in thread
From: Andrej Borsenkow @ 1998-08-26 17:26 UTC (permalink / raw)
  To: B.Stephens, zsh-users



> -----Original Message-----
> From: B.Stephens@isode.com [mailto:B.Stephens@isode.com]
> Sent: Wednesday, August 26, 1998 9:13 PM
> To: zsh-users@math.gatech.edu
> Subject: Re: Command alias in non-command position
> 
> 
> "Zefram" <zefram@tao.co.uk> writes:
> 
> > alias sudo='sudo '
> > 
> > permits alias expansion of the word following an alias-expanded sudo.
> 
> Cool.  Presumably this works with
> 
> alias xargs='xargs '
> 
> too.  Now, what about find ... -exec?
> 
> 

And don't forget about 'sudo -u bor ...' as well ... But yes, as the first step it is cool :)

/andrej


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

* Re: Command alias in non-command position
  1998-08-26 16:35 ` Bruce Stephens
  1998-08-26 17:01   ` Zefram
@ 1998-08-26 17:36   ` Bart Schaefer
  1998-08-27  1:51     ` 'man' completion Gossamer
  1998-09-01 12:51     ` Command alias in non-command position Wayne Davison
  1 sibling, 2 replies; 14+ messages in thread
From: Bart Schaefer @ 1998-08-26 17:36 UTC (permalink / raw)
  To: Bruce Stephens, ZSH users mailing list

On Aug 26,  5:35pm, Bruce Stephens wrote:
} Subject: Re: Command alias in non-command position
}
} > sudo vi ...
} > 
} > The /usr/bin/vi is started instead of elvis.
} > 
} > Is there any easy way to use my lovely aliases in this case?
} 
} Could I define sudo somehow, to say that its first argument ought to
} be expanded as if it were in the command position?

Yes:

alias sudo='sudo '

The trailing space in the sudo alias tells zsh to also apply alias
expansion again to the next word that follows it.

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

Programmable spelling correction would be the next logical step after
programmable completion, I suppose.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: Command alias in non-command position
  1998-08-26 17:13     ` Bruce Stephens
  1998-08-26 17:26       ` Andrej Borsenkow
@ 1998-08-26 17:49       ` Bart Schaefer
  1 sibling, 0 replies; 14+ messages in thread
From: Bart Schaefer @ 1998-08-26 17:49 UTC (permalink / raw)
  To: Bruce Stephens, zsh-users

On Aug 26,  6:13pm, Bruce Stephens wrote:
}
} "Zefram" <zefram@tao.co.uk> writes:
} > alias sudo='sudo '
} 
} Cool.  Now, what about find ... -exec?

Well ... there's always

alias -g -- -exec='-exec '

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* 'man' completion
  1998-08-26 17:36   ` Bart Schaefer
@ 1998-08-27  1:51     ` Gossamer
  1998-08-27  9:14       ` Bruce Stephens
  1998-09-01 12:51     ` Command alias in non-command position Wayne Davison
  1 sibling, 1 reply; 14+ messages in thread
From: Gossamer @ 1998-08-27  1:51 UTC (permalink / raw)
  To: ZSH users mailing list


I have a nifty set of completion macros for man pages but unfortunately
they stop me from getting the filename completion when I'm specifying the
file directly, eg:

man ./goofey.1

Forget where I got the original manpage macros from, this is  it ...

# man: complete commands, otherwise complete by search of $MANPATH.
# This is placed as an all-encompassing pattern at the end because
# making it the default before the -x doesn't work.  (It becomes
# '-c + (-K 'match-man' -x ...), not (-c + -K 'match-man') -x ...).
# We also complete paths for -M (override manpath), commands for
# -P (pager) and disable for -S (search sections).  After an explicit
# number (which it helps to complete for you), these completion rules
# assume a thorough search is needed and no longer uses the '-c' hashed
# commands, relying entirely on what's really in the manpath.
compctl -x 'S[1][2][3][4][5][6][7][8][9]' -k '(1 2 3 4 5 6 7 8 9)' \
  - 'R[[1-9nlo]|[1-9](|[a-z]),^*]' -K 'match-man' \
  - 's[-M],c[-1,-M]' -g '*(-/)' \
  - 's[-P],c[-1,-P]' -c \
  - 's[-S],s[-1,-S]' -k '( )' \
  - 's[-]' -k '(a d f h k t M P)' \
  - 'p[1,-1]' -c + -K 'match-man' \
  -- man


Gossamer

-- 
: Gossamer     gossamer@tertius.net.au  | Xanadoodler
: http://www.tertius.net.au/~gossamer/  | And proud of it :)
: Non-cooperation with evil is as much a duty as cooperation with good.
: -- Mohandas Gandhi


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

* Re: 'man' completion
  1998-08-27  1:51     ` 'man' completion Gossamer
@ 1998-08-27  9:14       ` Bruce Stephens
  1998-08-27 17:09         ` Bart Schaefer
  0 siblings, 1 reply; 14+ messages in thread
From: Bruce Stephens @ 1998-08-27  9:14 UTC (permalink / raw)
  To: ZSH users mailing list

Gossamer <gossamer@tertius.net.au> writes:

> I have a nifty set of completion macros for man pages but unfortunately
> they stop me from getting the filename completion when I'm specifying the
> file directly, eg:
> 
> man ./goofey.1

Ah.  I think if you stick a -f right after the compctl, then that'll
give you filename completion too.

compctl -f -x 'S[1][2][3][4][5][6][7][8][9]' -k '(1 2 3 4 5 6 7 8 9)' \
  - 'R[[1-9nlo]|[1-9](|[a-z]),^*]' -K 'match-man' \
  - 's[-M],c[-1,-M]' -g '*(-/)' \
  - 's[-P],c[-1,-P]' -c \
  - 's[-S],s[-1,-S]' -k '( )' \
  - 's[-]' -k '(a d f h k t M P)' \
  - 'p[1,-1]' -c + -K 'match-man' \
  -- man


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

* Re: 'man' completion
  1998-08-27  9:14       ` Bruce Stephens
@ 1998-08-27 17:09         ` Bart Schaefer
  1998-08-28 16:42           ` Sven Guckes
  0 siblings, 1 reply; 14+ messages in thread
From: Bart Schaefer @ 1998-08-27 17:09 UTC (permalink / raw)
  To: ZSH users mailing list

On Aug 27, 10:14am, Bruce Stephens wrote:
} Subject: Re: 'man' completion
}
} Gossamer <gossamer@tertius.net.au> writes:
} 
} > I have a nifty set of completion macros for man pages but unfortunately
} > they stop me from getting the filename completion when I'm specifying the
} > file directly
} 
} Ah.  I think if you stick a -f right after the compctl, then that'll
} give you filename completion too.

Yes, that's right, but it might be preferable to use -g with the same
pattern that's in the R[] expression:

	compctl -/ -g '*.([1-9nlo]|[1-9](|[a-z]))' ...

Also, I don't know what the "match-man" function does, but if it's nothing
more than a search of $MANPATH as Gossamer's comment suggested, then it
can be replaced with

	-g "${(@)^${(s(:))MANPATH}}/*/*.([1-9nlo]|[1-9](|[a-z]))(:t:r)"

The only missing bit being that if you want to use the section number to
restrict the search (i.e. "man 5 x<TAB>" completes only to "xferlog" and
not to "xterm" etc.), then you need a function.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: 'man' completion
  1998-08-27 17:09         ` Bart Schaefer
@ 1998-08-28 16:42           ` Sven Guckes
  1998-08-28 17:58             ` Bart Schaefer
  0 siblings, 1 reply; 14+ messages in thread
From: Sven Guckes @ 1998-08-28 16:42 UTC (permalink / raw)
  To: ZSH users mailing list

Quoting Bart Schaefer (schaefer@brasslantern.com):
> The only missing bit being that if you want to use the section
> number to restrict the search (i.e. "man 5 x<TAB>" completes only
> to "xferlog" and not to "xterm" etc.), then you need a function.

Such as?  ;-)

I presume there must be some non-plus-ultra completion control for "man".
But which *is* the best?

Sven  [hoping to see more of this on this maillist]


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

* Re: 'man' completion
  1998-08-28 16:42           ` Sven Guckes
@ 1998-08-28 17:58             ` Bart Schaefer
  1998-08-30 17:03               ` maillist archive lacking search engine Sven Guckes
  0 siblings, 1 reply; 14+ messages in thread
From: Bart Schaefer @ 1998-08-28 17:58 UTC (permalink / raw)
  To: Sven Guckes, ZSH users mailing list

On Aug 28,  6:42pm, Sven Guckes wrote:
> Subject: Re: 'man' completion
>
> Quoting Bart Schaefer (schaefer@brasslantern.com):
> > The only missing bit being that if you want to use the section
> > number to restrict the search (i.e. "man 5 x<TAB>" completes only
> > to "xferlog" and not to "xterm" etc.), then you need a function.
> 
> Such as?  ;-)

Uhh, such as

function complete_man_in_section {
  emulate -R zsh
  setopt localoptions nullglob
  local args
  read -Ac args
  args=(${args:#-*})	# Delete all words beginning with "-"
  reply=(${(s(:))^MANPATH}/man$args[2]/*.([1-9nlo]|[1-9](|[a-z]))(:t:r))
}

> I presume there must be some non-plus-ultra completion control for "man".
> But which *is* the best?
> 
> Sven  [hoping to see more of this on this maillist]

There have been more different "man" completions posted to zsh mailing lists
than any other sample completion.  Look through the archives on www.zsh.org.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: maillist archive lacking search engine
  1998-08-28 17:58             ` Bart Schaefer
@ 1998-08-30 17:03               ` Sven Guckes
  0 siblings, 0 replies; 14+ messages in thread
From: Sven Guckes @ 1998-08-30 17:03 UTC (permalink / raw)
  To: ZSH users mailing list

Quoting Bart Schaefer (schaefer@brasslantern.com):
> There have been more different "man" completions posted to zsh mailing lists
> than any other sample completion.  Look through the archives on www.zsh.org.

Been there, done that.  I tried to have a look at the index of the
zsh workers maillist of 1998, so I had to download 65K+ for this.
And then I am supposed to download every single article in hope
that it *might* contain what I am looking for you?  Forget it.

This either needs a good search engine or someone to summarize the contents.
Until then I would not point anyone to the archive - it isn't helpful.

Sven


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

* Re: Command alias in non-command position
  1998-08-26 17:36   ` Bart Schaefer
  1998-08-27  1:51     ` 'man' completion Gossamer
@ 1998-09-01 12:51     ` Wayne Davison
  1 sibling, 0 replies; 14+ messages in thread
From: Wayne Davison @ 1998-09-01 12:51 UTC (permalink / raw)
  To: ZSH users mailing list

"Bart Schaefer" wrote:
> Bruce Stephens wrote:
> } Could I define sudo somehow, to say that its first argument ought to
> } be expanded as if it were in the command position?
> 
> alias sudo='sudo '

Very nice.  There is a problem, however:

% alias cp='nocorrect cp'
% alias sudo='sudo '
% sudo cp foo bar
sudo: nocorrect: command not found

I assume there is a similar problem with the other pre-command
modifiers.

..wayne..


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

end of thread, other threads:[~1998-09-01 13:41 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-08-26 15:42 Command alias in non-command position Andrej Borsenkow
1998-08-26 16:35 ` Bruce Stephens
1998-08-26 17:01   ` Zefram
1998-08-26 17:13     ` Bruce Stephens
1998-08-26 17:26       ` Andrej Borsenkow
1998-08-26 17:49       ` Bart Schaefer
1998-08-26 17:36   ` Bart Schaefer
1998-08-27  1:51     ` 'man' completion Gossamer
1998-08-27  9:14       ` Bruce Stephens
1998-08-27 17:09         ` Bart Schaefer
1998-08-28 16:42           ` Sven Guckes
1998-08-28 17:58             ` Bart Schaefer
1998-08-30 17:03               ` maillist archive lacking search engine Sven Guckes
1998-09-01 12:51     ` Command alias in non-command position 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).