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

Tip of the day: some glob selectors



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



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