zsh-users
 help / color / mirror / code / Atom feed
* Tip of the day: some glob selectors
@ 2005-01-06 16:09 Peter Stephenson
  0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 2005-01-06 16:09 UTC (permalink / raw)
  To: Zsh users list

Oliver wrote a section for the book on how to use the "e" glob
qualifier which made me think of some other uses.

Often I want to select a whole set of files that are newer than a given
file, for example to back up files changed since the last backup.
Here's a function to do that:

nt() {
  if [[ -n $1 ]]; then
    local NTREF=${~1}
  fi
  [[ $REPLY -nt $NTREF ]]
}

You use it as follows:

NTREF=/reference/file
ls -l *(e:nt:)

This lists all the files in the current directory newer than the
reference file.

You can also specify the reference file inline; note quotes:

ls -l *(e:'nt ~/.zshenv':)


Another use is a quick way of turning the path to a file in Cygwin into
Cygwin notation, for passing as the argument to a Windows command:

cyg() {
  reply=("$(cygpath -w $REPLY)")
}

Now

explorer ~(e:cyg:)

is enough to convert ~ to the Cygwin form.


I wonder if it's a useful addition to allow

ls -l *(+nt)
explorer ~(+cyg)

as a shorthand?  The + would swallow up, say, all characters that can
appear in an identifier (alphanumerics plus underscore) and save it as
the command.  This would mean you could even chain them: *(+nt+cyg).
With arguments you're stuck with the long syntax, however.

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-01-06 16:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-06 16:09 Tip of the day: some glob selectors Peter Stephenson

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