Skew-T Meteorologist in Kansas City

fzf, ripgrep, git grep

Recent work has found me searching through large directory structures for files with sometimes less than obvious names. grep -r had become a go-to but it's not particularly speedy. Seeing a mention or two on Twitter led me to ripgrep which is specifically designed for such recursive file content searches. It also handily ignores files specified by gitignore and hidden files by default. Discovering ripgrep reminded me I had forgotten all about git grep which also allows for recursive searches, taking advantage of the git index, for files already in a repo.

fzf is a fuzzy finder, presenting an interactive way to search lists like filenames and git commits. Setting up aliases add useful interactivity to common tools, enabling quick full searching at the prompt in addition to the usual tab completion. As an example, searching recursively for a file, presenting a list of matches, and opening the selected in vim, bypassing the list if just one match.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
fe() {
  local IFS=$'\n'
  local files=()
  files=(
    "$(rg --files | fzf-tmux \
          --query="$1" \
          --multi \
          --select-1 \
          --exit-0
    )"
  ) || return
  "${EDITOR:-vim}" "${files[@]}"
}