Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Expanding interactively aliases
- X-seq: zsh-workers 13532
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: Expanding interactively aliases
- Date: Mon, 26 Feb 2001 13:32:05 +0100 (MET)
- In-reply-to: Peter Stephenson's message of Tue, 20 Feb 2001 19:02:31 +0000
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
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@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author