Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: global aliases and scripts in $path
- X-seq: zsh-users 10692
- From: Frank Terbeck <ft@xxxxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: global aliases and scripts in $path
- Date: Thu, 07 Sep 2006 21:20:13 +0200
- In-reply-to: <8fa44mahj1nj$.1fkuabkux8c7f.dlg@xxxxxxxxxx>
- Mail-followup-to: zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Operating-system: Linux 2.6.16.16 i686
- References: <8fa44mahj1nj$.1fkuabkux8c7f.dlg@xxxxxxxxxx>
Thorsten Kampe <thorsten@xxxxxxxxxxxxxxxx>:
> I've got a few global aliases[1] that allow me run my preferred
> scripts without the "./" nuisance (no I generally don't want the
> current folder in my path because of the security implications).
>
> [1] alias -s exe=wine \
> py=python \
> zsh=zsh
These are not global, but suffix aliases.
For a disambiguation of the two, see:
<http://zshwiki.org/home/examples/aliasglobal>
<http://zshwiki.org/home/examples/aliassuffix>
> This works fine but a few apps in /bin have an extension. So when I
> type rst2html.py (which is in /bin) python says it can't find the file
> (yep, it's not in the current directory).
>
> Is there a way out of this dilemma - meaning keeping the useful global
> alias and also be able to run files in $path who have an aliases
> extension?!
If you do this because of your "preferred scripts", as you said,
create a new directory ~/bin and put your scripts in there, and add
that directory to your path: path=( ~/bin $path );
That way you can call your scripts like normal programs (which is
preferable, IMHO).
If you want those suffix aliases by all means, the only solution I can
think of is this:
[snip]
zsh% print =pv.sh
/usr/bin/pv.sh
zsh% pv.sh
usage: /usr/bin/pv.sh page_number file_name[.dvi]
zsh% alias -s sh=/bin/sh
zsh% pv.sh
/bin/sh: Can't open pv.sh
zsh% alias pv.sh=/usr/bin/pv.sh
zsh% pv.sh
usage: /usr/bin/pv.sh page_number file_name[.dvi]
[snap]
You would have to create aliases for all commands in your $path that
end in the extensions you got suffix-aliases. That could be done in a
loop:
[snip]
extensions=( exe py zsh )
for binary in ${^path}/**/*.${^extensions}(N) ; do
command=${binary:t}
alias $command=$binary
done
[snap]
Though, I would prefer the ~/bin solution.
Regards, Frank
Messages sorted by:
Reverse Date,
Date,
Thread,
Author