* Re: Expanding interactively aliases
[not found] <Tc0a8890c51d8f3b42a@mailsweeper01.cambridgesiliconradio.com>
@ 2001-02-20 19:02 ` Peter Stephenson
0 siblings, 0 replies; 7+ messages in thread
From: Peter Stephenson @ 2001-02-20 19:02 UTC (permalink / raw)
To: Zsh hackers list
I wrote:
> expand-alias() {
> # for safety, in case there's an = which will mess things up...
> local alias=${LBUFFER#*=}
>
> if ! alias=$(alias $LBUFFER); then
> zle beep
> return 1
> fi
>
> LBUFFER=${(Q)${alias#*=}}
> }
> zle -N expand-alias
> bindkey '^xa' expand-alias
Here's this as a completer, _expand_alias. I decided there wasn't enough
common ground with _expand to put it there.
Could be tweaked:
- checking for being the first word isn't good enough for knowing whether
aliases should be expanded
- probably need some other way of skipping it --- you may find you
want to complete a command rather than expanding an alias
- should probably be some style to force expansion in any position.
- Sven can probably do it better anyway.
No documentation until all this gets decided. Just stick it in your list
of completers around where _expand goes or would go.
## --- start --- ##
#autoload
local word tmp expl
# Completer to expand aliases. Doesn't seem to have enough natural
# connection with normal expansion to put it in _expand.
if [[ "$funcstack[2]" = _prefix ]]; then
word="$IPREFIX$PREFIX$SUFFIX"
else
word="$IPREFIX$PREFIX$SUFFIX$ISUFFIX"
fi
[[ $CURRENT -eq 1 ]] || return 1
tmp="$(alias ${word#*=} 2>/dev/null)" || return 1
_wanted aliases expl alias compadd -UQ ${(Q)${tmp#*=}}
## --- end --- ##
--
Peter Stephenson <pws@csr.com> Software Engineer
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Expanding interactively aliases
2001-02-26 12:32 Sven Wischnowsky
@ 2001-02-26 12:48 ` Peter Stephenson
0 siblings, 0 replies; 7+ messages in thread
From: Peter Stephenson @ 2001-02-26 12:48 UTC (permalink / raw)
To: Zsh hackers list
> This is probably overkill...
It's ten years too late to worry about that. I don't see any problem.
Space for a couple of dozen lines of shell function no-one has to use isn't
going to worry anyone (so long as the defaults make it work naturally, of
course, which they do).
> It alwasy tries to expand global aliases everywhere, maybe that should
> be configurable, too.
I can see an argument for being able to choose via a style. Then using tag
aliases you can effectively make _expand_aliases into different
commands/completers for completing or expanding command or global aliases.
Now if you're *really* looking for overkill, there's the feature that
aliases whose text ends with a space cause expansion of subsequent words as
aliases...
--
Peter Stephenson <pws@csr.com> Software Engineer
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Expanding interactively aliases
@ 2001-02-26 12:32 Sven Wischnowsky
2001-02-26 12:48 ` Peter Stephenson
0 siblings, 1 reply; 7+ messages in thread
From: Sven Wischnowsky @ 2001-02-26 12:32 UTC (permalink / raw)
To: zsh-workers
This is probably overkill...
The _expand_alias can be used both as a completer and as a stand-alone
command. It can be configured with three boolean styles:
- always-regular: expand regular aliases even if not in command
position
- disabled: expand disabled aliases, too
- complete: (only if used as a command) if the word isn't a
alias, complete aliases
It alwasy tries to expand global aliases everywhere, maybe that should
be configurable, too.
No docs because I don't know if this should go in.
_expand_alias:
------------------------------------------------------------
local word expl tmp pre sel what
setopt localoptions
if [[ -n $funcstack[2] ]]; then
if [[ "$funcstack[2]" = _prefix ]]; then
word="$IPREFIX$PREFIX$SUFFIX"
else
word="$IPREFIX$PREFIX$SUFFIX$ISUFFIX"
fi
pre=()
else
local curcontext="$curcontext"
if [[ -z "$curcontext" ]]; then
curcontext="expand-alias-word:::"
else
curcontext="expand-alias-word:${curcontext#*:}"
fi
word="$IPREFIX$PREFIX$SUFFIX$ISUFFIX"
pre=(_main_complete - aliases)
fi
if [[ CURRENT -eq 1 ]]; then
sel=rg
else
sel=g
fi
zstyle -t ":completion:${curcontext}:" always-regular && sel="${sel}r"
zstyle -t ":completion:${curcontext}:" disabled && sel="${sel}${(U)sel}"
[[ $sel = *r* ]] && tmp=$aliases[$word]
[[ -z $tmp && $sel = *g* ]] && tmp=$galiases[$word]
[[ -z $tmp && $sel = *R* ]] && tmp=$dis_aliases[$word]
[[ -z $tmp && $sel = *G* ]] && tmp=$dis_galiases[$word]
if [[ -n $tmp ]]; then
$pre _wanted aliases expl alias compadd -UQ ${(Q)tmp}
elif (( $#pre )) && zstyle -t ":completion:${curcontext}:" complete; then
$pre _aliases -s "$sel"
else
return 1
fi
------------------------------------------------------------
And changing _aliases to:
------------------------------------------------------------
#compdef alias unalias
local expl sel args
zparseopts -E -D s:=sel
[[ -z $sel ]] && sel=rg
args=()
[[ $sel = *r* ]] && args=( $args 'aliases:regular alias:compadd -k aliases' )
[[ $sel = *g* ]] && args=( $args 'global-aliases:global alias:compadd -k galiases' )
[[ $sel = *R* ]] && args=( $args 'disabled-aliases:disabled regular alias:compadd -k dis_aliases' )
[[ $sel = *G* ]] && args=( $args 'disabled-global-aliases:disabled global alias:compadd -k dis_galiases' )
_alternative $args
------------------------------------------------------------
Bye
Sven
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Expanding interactively aliases
2001-02-21 8:42 ` Andrej Borsenkow
@ 2001-02-21 10:50 ` Geoff Wing
0 siblings, 0 replies; 7+ messages in thread
From: Geoff Wing @ 2001-02-21 10:50 UTC (permalink / raw)
To: zsh-workers
Andrej Borsenkow <Andrej.Borsenkow@mow.siemens.ru> typed:
:> And the maling list archive seems to be defunct -- I always get zero
:> metches no matter what I'm searching for.
:Disk full again? At least, it was the reason last time ...
Sorry, it was the workers search which was down due to resource limits -
it hit the fd limit. users was still up. Searching zsh-workers is going
again now.
Regards,
--
Geoff Wing : <gcw@pobox.com>
Rxvt Stuff : <gcw@rxvt.org>
Zsh Stuff : <gcw@zsh.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Expanding interactively aliases
2001-02-21 8:19 Sven Wischnowsky
@ 2001-02-21 8:42 ` Andrej Borsenkow
2001-02-21 10:50 ` Geoff Wing
0 siblings, 1 reply; 7+ messages in thread
From: Andrej Borsenkow @ 2001-02-21 8:42 UTC (permalink / raw)
To: zsh-workers
>
> And the maling list archive seems to be defunct -- I always get zero
> metches no matter what I'm searching for.
>
Disk full again? At least, it was the reason last time ...
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Expanding interactively aliases
@ 2001-02-21 8:19 Sven Wischnowsky
2001-02-21 8:42 ` Andrej Borsenkow
0 siblings, 1 reply; 7+ messages in thread
From: Sven Wischnowsky @ 2001-02-21 8:19 UTC (permalink / raw)
To: zsh-workers
Oliver Kiddle wrote:
> ...
>
> My real point is that the existing _expand appears to be expanding global
> aliases already. I wouldn't have expected this because -U is used when
> autoloading _expand. A quick check reveals that this is with the
> substitute style and is due to the fact that the aliases are expanded
> within eval.
Now that you say that... I seem to have a very faint memory of a
discussion about this (not in _expand, I think, we had the problem
somewhere else). I think we found a solution which I can't think of
now and I don't know where to search for it either.
And the maling list archive seems to be defunct -- I always get zero
metches no matter what I'm searching for.
Hm. Anyone else remember this?
> I don't think it is ideal that autoload -U functions are subject to
> aliases within eval and you could probably break a few bits of completion
> with certain global aliases. Would it be easy to avoid this somehow? The
> other solution would be a -U argument to eval which probably isn't a great
> idea because eval currently takes no options.
That aliases-inside--U-functions isn't that easy, I think (and there
may be cases where the function wants to have them expanded but the
user loaded it with -U, without thinking about this side-effect).
Bye
Sven
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Expanding interactively aliases
@ 2001-02-20 18:54 Oliver Kiddle
0 siblings, 0 replies; 7+ messages in thread
From: Oliver Kiddle @ 2001-02-20 18:54 UTC (permalink / raw)
To: zsh-workers
Peter Stephenson wrote (on zsh-users):
> Quite possibly Sven has already added an option to the _expand
> completer by now, otherwise I'll try and remember to look at that.
I had a quick look at _expand and, as I thought there is nothing to
explicitly expand aliases. I thought about adding it myself and had in
mind something along the lines of:
if zstyle -T ":completion:${curcontext}:" aliases; then
(( CURRENT == 1 )) || exp=( "$exp[@]" "$aliases[$words[1]]" )
exp=( "$exp[@]" "$galiases[$words[CURRENT]]" )
fi
This is fairly irrelevant and don't expect that to work because I've not
really tried it.
My real point is that the existing _expand appears to be expanding global
aliases already. I wouldn't have expected this because -U is used when
autoloading _expand. A quick check reveals that this is with the
substitute style and is due to the fact that the aliases are expanded
within eval.
I don't think it is ideal that autoload -U functions are subject to
aliases within eval and you could probably break a few bits of completion
with certain global aliases. Would it be easy to avoid this somehow? The
other solution would be a -U argument to eval which probably isn't a great
idea because eval currently takes no options.
And, BTW, alias has a -L option which you could have used in your
edit-alias function. Especially handy if you alias' name starts with '-'.
Oliver Kiddle
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2001-02-26 12:49 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <Tc0a8890c51d8f3b42a@mailsweeper01.cambridgesiliconradio.com>
2001-02-20 19:02 ` Expanding interactively aliases Peter Stephenson
2001-02-26 12:32 Sven Wischnowsky
2001-02-26 12:48 ` Peter Stephenson
-- strict thread matches above, loose matches on Subject: below --
2001-02-21 8:19 Sven Wischnowsky
2001-02-21 8:42 ` Andrej Borsenkow
2001-02-21 10:50 ` Geoff Wing
2001-02-20 18:54 Oliver Kiddle
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).