find(1) の私なりの短縮版シェル関数

find(1) を使って,第1引数を名前に含む(「一致」ではない)ファイルまたはディレクトリを第2引数のディレクトリ(省略可,cwdがデフォルト値)から列挙するシェル関数.私の常用はZshだけどほぼBash互換だと思う.

function fnd {
  local pat=$1 dir=${2:-.}
  find "$dir" -type d \( -name .svn -o -name .git -o -name .hg -o -name CVS \) -prune -o -iname "*$pat*" -print
}

用例:

$ fnd ether /usr/include
/usr/include/linux/bpqether.h
/usr/include/linux/if_ether.h
/usr/include/net/ethernet.h
/usr/include/netinet/if_ether.h
/usr/include/netinet/ether.h
$ cd /usr/include/netinet
$ fnd ether
./if_ether.h
./ether.h

最近 grep(1) の代わりに ack(1) を使っていて便利に感じているが,それと似た流れが find(1) にも欲しかった.