zsh で ack like な検索

まぁ、ネタです。言語とか選べないし遅い。利点はせいぜいテキストファイルかバイナリファイルかを自動認識するくらい。

autoload -U colors

function grepfind() {
    pat=$1

    find -type d \( -name .svn -o -name CVS -o -name RCS \
        -o -name _darcs -o -name blib \) -prune \
        -o -type f | perl -ne 'chomp; print $_, "\n" if -T' | \
        while read filename line;
          do
          matched=$(grep --color=always -n -e "$pat" "$filename")
          if [ "x$matched" != x ]; then
              echo "$bold_color$fg[green]$filename$reset_color"
              echo "$matched"
              echo
          fi
        done
}

グルーピングいらね、って人は下記で。

function grepfind() {
    find -type d \( -name .svn -o -name CVS -o -name RCS \
        -o -name _darcs -o -name blib \) -prune \
        -o -type f | perl -ne 'chomp; print $_, "\0" if -T' |
        xargs -0 -e grep -n -e "$1" /dev/null
}