2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

grep で特定ファイルを無視をしたい

Last updated at Posted at 2020-09-30

git grep と ripgrep で特定のファイル/ディレクトリを無視をしたい

git grep

リポジトリ毎に指定したかったので,.git/config に指定した

.git/config
[grep]
    defaultFile = :!ignoredDirectory
~/.zshrc
function gg () {
  git grep $* `git config grep.defaultFile`
}

rg も同じ設定を使いたい

~/.zshrc
export RG_DEFAULT_OPT='-p'
function rg() {
  # separated by :
  typeset -a glob;
  for p in ${(@s.:.)$(git config grep.defaultFile)}; do
    glob+=(--glob $p)
  done
  command rg $RG_DEFAULT_OPT "$@" "${(@)glob}"
}

古いもの(クォートがうまくない)

~/.zshrc
export RG_DEFAULT_OPT='-p'
function rg() {
  local glob=`git config grep.defaultFile | sed -e 's/:/--glob /g'`
  if [[ ! -z "$glob" ]]; then
    eval command rg $RG_DEFAULT_OPT $* $glob
  else
    eval command rg $RG_DEFAULT_OPT $*
  fi
}

! しか無い前提だけど,とりあえずこれでやりたいことはできる.

LINK

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?