zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh User <zsh-users@sunsite.dk>
Subject: Re: which-command help
Date: Tue, 17 May 2005 16:55:30 +0100	[thread overview]
Message-ID: <200505171555.j4HFtUOb012962@news01.csr.com> (raw)
In-Reply-To: <1050517153211.ZM27474@candle.brasslantern.com>

Bart Schaefer wrote:
> On May 17,  3:47pm, Peter Stephenson wrote:
> } Subject: Re: which-command help
> }
> } > # but if I use "^[?" (is which-command) I get:
> } > 
> } >  ~ % which-command /bin/ls
> } > /bin/ls
> } 
> } The problem is that the processing of which-command within the editor
> } expands the alias, so that the command line that which-command sees
> } already has the /bin/ls expanded.
> } 
> } I think this is a bug, fixed below: we don't want to expand aliases when
> } getting the name of the command.
> 
> Compare zsh-workers/20895 and surrounding thread.  Are we breaking one
> thing to fix another?

Well, your reply in that message was:

> Suppose you have
> 
>   alias LL='ls -lL'
> 
> Do you want run-help to display the man page for "ls", or do you want it
> to simply fail because there is no LL command?

Actually, it *doesn't* fail after the patch:

% alias LL='ls -lL'
% which-command LL
ls -lL

I would have said that's more useful, because it's clearer about what's
going on (even more so if which-command is aliased to something more
verbose).  However, I'm certainly not set on the patch.  I would be
happy to suggest using the editor widget instead.  That could even be
modified to expand the alias and lookup the first word as a command,
noting that aliases work recursively:

which-command() {
  zmodload -i zsh/parameter

  zle -I
  local -a wds
  wds=(${(z)LBUFFER})
  local wd=${wds[1]}
  local rawwd=${(Q)wd}
  local -A seen

  while true; do
    wd=${wds[1]}
    rawwd=${(Q)wd}

    # replace "whence -c" with your favourite function
    # (but NOT which-command!)
    if [[ $rawwd != $wd || -n $seen[$rawwd] ]]; then
      # quoted or already expanded, don't expand alias
      (unalias -- $rawwd 2>/dev/null; whence -c $rawwd)
    else
      # turn on globsubst for =ls etc.
      whence -c ${~rawwd}
      if [[ -n $aliases[$rawwd] && -z $seen[$rawwd] ]]; then
        # Recursively expand aliases
        seen[$rawwd]=1
        wds=(${(z)aliases[$rawwd]})
	continue
      fi
    fi
    break
  done
}

This might be worth sticking in Functions/Zle.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

**********************************************************************


  reply	other threads:[~2005-05-17 15:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-17 13:20 Francisco Borges
2005-05-17 14:47 ` Peter Stephenson
2005-05-17 15:32   ` Bart Schaefer
2005-05-17 15:55     ` Peter Stephenson [this message]
2005-05-17 17:06       ` Bart Schaefer
2005-05-17 17:47         ` Peter Stephenson
2005-05-18 10:27       ` PATCH: " Peter Stephenson

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=200505171555.j4HFtUOb012962@news01.csr.com \
    --to=pws@csr.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@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).