zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: Re: Expanding interactively aliases
Date: Tue, 20 Feb 2001 19:02:31 +0000	[thread overview]
Message-ID: <Tc0a8890c51d9a7da79@mailsweeper01.cambridgesiliconradio.com> (raw)
In-Reply-To: Your message of "Tue, 20 Feb 2001 15:45:44 GMT." <Tc0a8890c51d8f3b42a@mailsweeper01.cambridgesiliconradio.com>

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


       reply	other threads:[~2001-02-20 19:03 UTC|newest]

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

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=Tc0a8890c51d9a7da79@mailsweeper01.cambridgesiliconradio.com \
    --to=pws@csr.com \
    --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).