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

Re: http://grml.org/zsh/zsh-lovers.html

On Mon, Aug 15, 2011 at 12:28 PM, TJ Luoma <luomat@xxxxxxxxx> wrote:
> Even some things like:
>   $f:e = file extension
>   $f:h = head (dirname)
>   $f:t = tail (basename)
>   $f:r = rest (extension removed)
> The number of times I've called `basename` or used `sed` to get a
> file's extension…

Oh, I REALLY love these. I use them all the time now, in various ways.
Also great that they usually don't require the {}s.

There's a nice mnenoic that works for these -- I use ERTH (like Earth).

  ER: Extension, Remove
  TH: Tail, Head (instead of basename/dirname which I've always hated)

Some (slightly contrived) use cases:

  % something foo.png
  % other !$:r  # foo

  % cp somefile.html /other/place/foo.html
  % cd !$:h

  [[ $myfile:e == xml ]] ...

  print "
usage: $0:t ..."

Chaining is also really cool:



There are tons of other places where I've replaced use of

twitter:@Membean  |  email:Micah@xxxxxxxxxxx  |  http://Membean.com
Remember your words with Membean! Three free days of learning!

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