Is zsh turing-complete yet?
Ted Leung mentioned one of the
"Things I never
knew about zsh, and in a comment, Olifante mentioned the "vared"
command -- which was one of the things I never knew about zsh.
Cool, thanks, Olifante.
One of my favorite zsh features is patterns like
"*(^/)
" -- all the non-directories in $PWD
.
And the "$=foo
" vs "$==foo
"
that lets you control whether to break up the foo variable's
contents into space-separated words, or not.
I compared various Unix shells
here,
and made a still-unrealized not-quite-resolution
here.
I have a set of zsh startup files that is almost in the
direction of O-O programming. My intent is to make it so
that I don't have to modify very many existing files any time
I move my environment to a new system -- just add new ones
for the new system.
For the most part, I do this by making most of the setup
commands exist as files in my $FPATH autoload directory,
so that they can become shell functions when invoked. I
build up zsh-function names based on the hostname
(e.g., _zH_host1, _zH_host2), based on operating system
(e.g., _zO_cygwin, _zO_Solaris), and then execute the
autoload shell-function-file with that name, if it exists.
Next step, I suppose, would be to add employer- or
location-specific ones.
I suppose everyone has a favorite "cd/pushd/popd" set
of functions. Since mine are in zsh, all of them start with
"z". ("z" alone is just a pushd; I practically never use
a bare (non-pushd) cd -- I don't see the point.) zl is maybe
the most common command that I type: in effect, pushd to a
directory and then list it.
My favorite two cd-like commands are zq and zf (I keep
them in my autoload directory):
zq (q for "Query") cd's to the most recent directory in your dirstack
that contains the given pattern:
# function zq -- cd, qualified by searching the dirstack.
# take only the LAST (== most recent) directory that matches. NoIC.
# zq_dest=$( dh | grep "$1" | tail -1 )
zq_dest=$( dirs -v | grep "$1" | head -1 )
set -- $=zq_dest
echo z $2
eval z $2
And zf (f for "File") gets a filename as argument; it cd's
to the directory containing that file. Very handy for when
you can easily copy/paste a filename but don't want to waste
the time erasing the filename part of it. zf erases it for you.
# zf is "cd to a file's directory"
dir="${1%/*}"
z "$dir"
unset dir
z . # Make the window title look right.
9:23:47 PM