LoginSignup
15
11

More than 5 years have passed since last update.

rg(ripgrep)でinclude/excludeする

Last updated at Posted at 2018-04-30

コード

# include
rg foo -g '*.min.js'

# exclude
rg foo -g '!*.min.js'

!を使うとincludeがexcludeに切り替わる。-g--globのショートハンド。
急いで探しものをしているときとか、非常に助かります。

ちょっとした注意点

がいくつかありまして。

  • !(exclude)とクォートを組み合わせる時はシングルクォーテーションにする
    • ダブルクオーテーションだとヒストリ展開されてしまう
  • globの対象はファイルパス
    • ファイルの中身が対象ではないので注意

globしつつファイルの中身に対して絞り込み等をしたい場合は、最初の例のようにオプションなし引数で単語を渡すか、あるいは下記のように正規表現のオプション-eが使えます。

rg -e '^foo' -g '*.md'

参考

15
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
11