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

Re: alias -s doesn't friendly deal with programs having an extension

Maddi Kopfermann wrote:
> Hi, ZSH workers,
> after alias pl=perl e.g.
> a program with an extension like  e.g. program.pl can no
> longer be invoked without its full path.

In the case of Perl, the fix is simple:

  alias -s pl='perl -S'

(although the Perl documentation is now so complicated it took me five
minutes to confirm that...)

More generally, you could write a shell function to do this.

pathfind() {
  local dir
  for dir in $path; do
    if [[ -f $dir/$2 ]]; then
      $1 $dir/$2 "${(@)argv[3,-1]}"
  print pathfind: file not found in path: $2
  return 255
alias -s pl='pathfind perl'

Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070

To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php

To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview

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