0
Help us understand the problem. What are the problem?

posted at

updated at

Organization

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

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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
0
Help us understand the problem. What are the problem?