Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: autoload and alias expansion question
- X-seq: zsh-users 12636
- From: Peter Hegedus <hegedus@xxxxxxxxxxxxxxxx>
- To: Peter Stephenson <pws@xxxxxxx>
- Subject: Re: autoload and alias expansion question
- Date: Mon, 25 Feb 2008 13:40:47 -0500
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: Message from Peter Stephenson <pws@xxxxxxx> of "Mon, 25 Feb 2008 17:17:13 GMT." <200802251717.m1PHHDbO030294@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
Thanks for the quick answer!
I need it mostly for global aliases, to reduce clutter, for example
alias -g DN='>/dev/null 2>&1'
alias -g NE='2>/dev/null'
alias -g LF='>>$_LF 2>&1'
The separate file approach works, thanks, I just needed to added an
extra autoload wherever that base library was loaded.
Thanks,
Peter
>"Peter Hegedus" wrote:
>> hegedus@su20% cat >foobar <<EOF
>> foobar () { }
>> alias DATE=date ; barfoo () { setopt aliases ; DATE ; ECHO OK }
>> EOF
>> hegedus@su20% autoload foobar
>> hegedus@su20% foobar
>> hegedus@su20% barfoo
>> barfoo: command not found: DATE
>> OK
>
>> Do I miss something?
>
>No, you don't. Aliases are expanded very early, during the initial
>parsing of the code, so the DATE is reached and parsed before the alias
>command is run.
>
>> Is there a way to make this work?
>
>You have two obvious options.
>
>Firstly, most people when writing scripts or functions would use scripts
>or functions at this point anyway, i.e. DATE() { date; }. The main use
>of aliases is as a hack at the command line to save typing; they are
>rather less atractive if that's not an issue.
>
>Second, you can put the alias definitions in a separate file and ensure
>that that gets loaded before the function. There are various ways of
>doing this if that's what you really need. Until we know why you're not
>using a function for DATE it's hard to answer.
>
>--
>Peter Stephenson <pws@xxxxxxx> Software Engineer
>CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
>Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author