Howardism Musings from my Awakening Dementia
My collected thoughts flamed by hubris
Home PageSend Comment

zsh: Precommands and a Better Find

We all know about shell pre-command of exec which runs the command following it without forking a new shell. ZShell has a noglob pre-command… which tells the shell not to expand any glob expressions.

You may ask why:

noglob grep foo *.c

is better than:

grep foo '*.c'

Well, think of aliases. For example, I like the find command, and use it often, but it is a bit cumbersome and unwieldy, so, I often use a simpler wrapper function:

function findit {
   find . -iname '$*'
   # My actual function is a bit more complicated
}

If I create a noglob alias to this function:

alias f='noglob findit'

I can type the following without quotes:

f foo*.c

Since you probably never want glob expansions for files in the current directory when using the find command, you might want to do something like:

alias find='noglob find'

My findit is a bit more than just what I showed above (see the entire code), but I'm sure you've rolled yer own.

Tell others about this article:
Click here to submit this page to Stumble It