git grep がかなり便利
普段開発をしている中で、特定の単語でファイル内を手軽に検索したい場合がある。
もちろんソースコードをvscodeで開いて検索しても良いが、一工程加わるので、面倒な時がある。そんなときに git 管理しているものであれば、git grep コマンドが使える。
感覚的には Linux の locate コマンドに近い。
How to use?
$ git grep "検索したい文字列"
のような感じで使える。
例えば、以下を実行すると、
$ git grep 'def current_user'
下のような結果が得られる。
app/lib/inline_renderer.rb: def current_user
app/policies/application_policy.rb: def current_user
app/serializers/rest/announcement_serializer.rb: def current_user?
app/serializers/rest/poll_serializer.rb: def current_user?
app/serializers/rest/reaction_serializer.rb: def current_user?
app/serializers/rest/status_serializer.rb: def current_user?
app/serializers/rest/tag_serializer.rb: def current_user?
ちなみに上は、mastodon の repository を fork & clone してローカルで試した結果。
参考: https://github.com/mastodon/mastodon
他の使い方
公式ドキュメントには様々なオプションが載っている。
色々やってみると面白いかもしれない。