zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-users@sunsite.dk
Subject: Re: suffix alias
Date: Thu, 11 Nov 2004 15:31:39 +0000	[thread overview]
Message-ID: <21233.1100187099@csr.com> (raw)
In-Reply-To: <tps6j3c9v88g$.dlg@thorstenkampe.de>

Thorsten Kampe wrote:
> 
> Thanks. So there is no "builtin" solution for this. I thought of
> "command rst2html.py" which is a "kind of solution", too.

Generally speaking, shell functions are more flexible.  There's no real
gain from adding some kind of builtin support in a case like this.
Where you would need an internal change is if you wanted to match
files by patterns rather than suffixes.

> Could you explain a bit what your wrapping function does?

I thought someone might ask.

exec-py () {
  # Collect matches in local array files.  There might
  # be more than one match in $path.
  local -a files
  # This is a very common trick in zsh for searching paths.
  # ${^path}/$1 becomes $path[1]/$1 $path[2]/$1 ...
  # i.e. trial matches that might or might not be real files.
  # The (N) qualifier removes any elements that don't correspond to files.
  files=(${^path}/$1(N))
  # If we found a file, replace $1 by the path to the first match,
  # i.e. the earliest in the $path.
  # If we didn't find the file in path, leave the arguments alone.
  # A simpler version would be:
  #   (( ${#files} )) && 1=$files[1]
  (( ${#files} )) && set -- $files[1] "${(@)argv[2,-1]}"
  # Execute python with the original command line except with
  # $1 replaced as above.
  python "$@"
}
# Use the function instead of python for .py files.
alias -s py=exec-py

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


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


      reply	other threads:[~2004-11-11 15:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-11 14:28 Thorsten Kampe
2004-11-11 14:50 ` Peter Stephenson
2004-11-11 15:13   ` Thorsten Kampe
2004-11-11 15:31     ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=21233.1100187099@csr.com \
    --to=pws@csr.com \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).