Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Rationalized? aliases



>Hmm... A quick fix for your problem is to change
>printaliasnode() in hashtable.c so that when the flags
>PRINT_WHENCE_* are present, that it will use printf (or puts)
>instead of printquoted().  This is exactly how it was done in
>beta10.  But is this what we want to do?  It looks natural for
>the output of `type' and `which' to be quoted.  For `whence' it
>is not quite so clear which is best.

"whence" is supposed to be used by humans.  Its output should be
quoted.  Putting it in a command substitution is, and always was, a
kludge.  That's what equals substitution is for:

% alias foo=bar
% echo =foo
bar

but there is an inconsistency, in a way, between equals substitution of
normal commands and of aliases:

% whence 'a*b'
/dcs/94/zefram/bin/a*b
% echo ='a*b'
/dcs/94/zefram/bin/a*b
% ='a*b'
This is a script with a silly name.
% alias foobar='echo *'
% echo =foobar
echo *
% =foobar
zsh: command not found: echo *

Actually the inconsistency is not in the equals substitution itself,
but in the fact that the text it expands to will, in actual use, be
rescanned.  This limits the use of equals substitution a little.

I think for builtins and shell functions equals substitution should
expand to the command name, rather than its present behaviour of
failing.  Then equals substitution will be usable in functions in an
interesting way:

function foo {
  local savecmd==$1 evalhack=
  alias $1 >&- && evalhack=eval
  # some commands that mess up PATH or whatever
  $=evalhack $savecmd some args
  # more commands
}

Maybe there should be another syntax similar to equals substitution --
say, ==command -- that puts an extra layer of quoting on the
substituted filename unless the command is an alias.  That would make
the above function:

function foo {
  local savecmd===$1 evalhack=
  # some commands that mess up PATH or whatever
  alias savedcmd=$savecmd
  savedcmd some args
  # more commands
}

Anyone got any better ideas?

-zefram



Messages sorted by: Reverse Date, Date, Thread, Author