From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22319 invoked from network); 26 Feb 2001 12:32:20 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 26 Feb 2001 12:32:20 -0000 Received: (qmail 15919 invoked by alias); 26 Feb 2001 12:32:13 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 13532 Received: (qmail 15907 invoked from network); 26 Feb 2001 12:32:12 -0000 Date: Mon, 26 Feb 2001 13:32:05 +0100 (MET) Message-Id: <200102261232.NAA18757@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@sunsite.dk In-reply-to: Peter Stephenson's message of Tue, 20 Feb 2001 19:02:31 +0000 Subject: Re: Expanding interactively aliases 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