summaryrefslogtreecommitdiff
path: root/seek
blob: 76382b731f97bbe20fa7612302c246f0e440fc95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash
set -euo pipefail
RG_DEFAULT_COMMAND="rg --ignore-case --files-with-matches $*"
INITIAL_QUERY=""
readarray -t selected <<< "$(fzf \
  --multi \
  --exact \
  --ansi \
  --disabled \
  --query "$INITIAL_QUERY" \
  --bind "ctrl-a:select-all" \
  --bind "esc:ignore" \
  --bind "ctrl-/:change-preview-window(90%|hidden|)" \
  --bind "alt-0:change-preview:rg --ignore-case --pretty --context 2 {q} {}" \
  --bind "alt-1:change-preview(bat -p --color always {})" \
  --bind "alt-2:change-preview(git log --color=always --date=relative --abbrev-commit --pretty=format:'%Cred%h%Creset %s / %an %Creset%C(yellow)%d%Creset%Cgreen(%cr)%Creset' -- {})" \
  --bind "alt-3:change-preview(git log --color=always {})" \
  --bind "alt-4:change-preview(git log --color=always -p {})" \
  --bind "alt-5:change-preview(git blame -c --date=short {})" \
  --bind "alt-6:change-preview(git log --pretty=short {} | git shortlog -nse)" \
  --bind "alt-7:change-preview(git log --pretty=short {} | git shortlog)" \
  --bind "pgup:preview-page-up" \
  --bind "pgdn:preview-page-down" \
  --bind "backward-eof:abort" \
  --bind "change:reload:$RG_DEFAULT_COMMAND {q} || true" \
  --print-query \
  --preview "rg --ignore-case --pretty --context 2 {q} {}" \
  --preview-window="down"
)"
query=${selected[0]}
files=("${selected[@]:1}")
if [[ -n "${files:-}" ]]
then
    # i don't think this works with emacs...
    ${EDITOR:-vim} "+/$query" "${files[@]}"
    for f in "${files[@]}"
    do
        echo "$f"
    done
fi