LoginSignup
9
10

More than 5 years have passed since last update.

git grep + pecoで選択したファイルをエディタで開く

Posted at

git grep便利ですよね。
git管理下にあるファイルに絞ってgrepしてくれます。
その結果をpecoを使ってさらに絞り込んで、選択した行をエディタで開くコマンドを書いてみました。

デモ

pecoとgitがインストールされている必要があります。

$ git-grep-edit word

git-grep-edit.gif

コード

コマンド自体は数行ですが、pecoとgitがインストールされている必要があります。

#!/bin/bash

P=$(git grep -n $1 | peco | awk -F: '{print "+"$2" "$1}')
if [ ${#P} -ne 0 ]; then
    $EDITOR $P;
fi

インストール

pathが通ったところに配置すれば使えますが、npmからインストールするのが手軽です。
nodeがインストールされている必要があります。

$ npm install -g git-grep-edit
9
10
1

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
9
10