zsh-workers
 help / color / mirror / code / Atom feed
From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.dk
Subject: Re: Expanding interactively aliases
Date: Mon, 26 Feb 2001 13:32:05 +0100 (MET)	[thread overview]
Message-ID: <200102261232.NAA18757@beta.informatik.hu-berlin.de> (raw)
In-Reply-To: Peter Stephenson's message of Tue, 20 Feb 2001 19:02:31 +0000


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


             reply	other threads:[~2001-02-26 12:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-02-26 12:32 Sven Wischnowsky [this message]
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
     [not found] <Tc0a8890c51d8f3b42a@mailsweeper01.cambridgesiliconradio.com>
2001-02-20 19:02 ` Peter Stephenson
2001-02-20 18:54 Oliver Kiddle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200102261232.NAA18757@beta.informatik.hu-berlin.de \
    --to=wischnow@informatik.hu-berlin.de \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).