gren - 次世代grepを目指したコマンドラインツール - 0.1.3は文字コード類推検索と、絞込み検索機能を追加

gren - gren is a next grep tool.

gren 0.1.3 をリリースしました。
今回の売りは二つ、文字コード類推検索と、絞込み検索機能です。

異なる文字コードのテキストファイルを同時に検索出来る機能は、コマンドラインツールでは今まで以外となかった(というか私が見つけられなかった)ので重宝しています。

絞込検索は、web検索等で良く使用する、含まれないキーワードを指定したり、いずれかのキーワードを含む行を探すのに便利な機能です。

結構便利になってきました。

文字コード類推検索

ディレクトリ内に、異なった文字コードのテキストが混じっていても正しく検索できます。
対応している文字コードは、

  1. SJIS
  2. JIS
  3. EUC
  4. ASCII
  5. UTF8
  6. UTF16

です。

    • encodeオプションを使うと、入力文字コードを明示的に指定することも出来ます。

特に指定しない場合、WindowsならばSJISとして、OSXならばUTF8として動作します。

絞込み検索(含まれない検索、OR検索に対応)

0.1.2からAND検索は出来ましたが、加えて含まれない検索、OR検索に対応しました。

  • --subで指定したキーワードは、行に''含まれない''キーワードです。
  • --orで指定したキーワードは、''いずれかを含む''キーワードです。

例1. "test"を含み、かつ"FILE"を含まない行を出力

% gren test --sub FILE
Manifest.txt:16:test/test_gren.rb
Manifest.txt:17:test/test_gren_cli.rb
Manifest.txt:18:test/test_helper.rb
.
.

例2. "test"を含み、かつ"FILE"を含まずに、"helper"か"default"を含む行を検索

% gren test --sub FILE --or helper --or default
Manifest.txt:18:test/test_helper.rb
pkg/gren-0.1.3/Manifest.txt:18:test/test_helper.rb
pkg/gren-0.1.3/README.rdoc:128: test/test_helper.rb
.
.

例3. OR検索だけでも検索可能 - "helper"か"default"を含む行を検索

% gren --or helper --or default
Manifest.txt:18:test/test_helper.rb
pkg/gren-0.1.3/Manifest.txt:18:test/test_helper.rb
pkg/gren-0.1.3/Rakefile:20:  self.rubyforge_name       = self.name # TODO this is default value
.
.

インストール

rubyがインストールされていれば、

Windows

gem.bat install gren

Mac OS X

sudo gem install gren

でインストール出来ます。

--help

0.1.3のオプション一覧です。

% gren -h
gren [option] pattern
        --sub PATTERN                Keyword is not included.
        --or PATTERN                 Either of keyword is contained.
    -d, --directory DIR              Start directory. (deafult:".")
        --depth DEPTH                Limit search depth. 
        --this                       "--depth 0"
    -i, --ignore                     Ignore case.
    -s, --silent                     Silent. Display match line only.
        --debug                      Debug display.
    -c, --color                      Color highlight.
    -f, --file-regexp REGEXP         Search file regexp. (Enable multiple call)
        --if, --ignore-file REGEXP   Ignore file pattern. (Enable multiple call)
        --id, --ignore-dir REGEXP    Ignore dir pattern. (Enable multiple call)
    -e, --encode ENCODE              Specify encode(none, auto, jis, sjis, euc, ascii, utf8, utf16). Default is "auto"