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

Re: global aliases and scripts in $path

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:

> 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:

zsh% print =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]

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

extensions=( exe py zsh )
for binary in ${^path}/**/*.${^extensions}(N) ; do
  alias $command=$binary

Though, I would prefer the ~/bin solution.

Regards, Frank

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