zsh-users
 help / color / mirror / code / Atom feed
* global aliases and scripts in $path
@ 2006-09-07 18:41 Thorsten Kampe
  2006-09-07 19:20 ` Frank Terbeck
  0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Kampe @ 2006-09-07 18:41 UTC (permalink / raw)
  To: zsh-users

Hi,

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).

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?!

Thorsten

[1] alias -s exe=wine  \
             py=python \
            zsh=zsh


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: global aliases and scripts in $path
  2006-09-07 18:41 global aliases and scripts in $path Thorsten Kampe
@ 2006-09-07 19:20 ` Frank Terbeck
  0 siblings, 0 replies; 2+ messages in thread
From: Frank Terbeck @ 2006-09-07 19:20 UTC (permalink / raw)
  To: zsh-users

Thorsten Kampe <thorsten@thorstenkampe.de>:
> 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-09-07 19:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-07 18:41 global aliases and scripts in $path Thorsten Kampe
2006-09-07 19:20 ` Frank Terbeck

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).