aboutsummaryrefslogtreecommitdiff
path: root/bin/rgf
blob: 49a9fe7ddb4c875c48d91109d801236029869858 (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
#!/usr/bin/env bash

set -o errexit
set -o nounset
if [[ "${TRACE-0}" == "1" ]]; then
    set -o xtrace
fi

main() {
  result=$(rg -L --ignore-case --color=always --line-number --no-heading "$@" |
    fzf --ansi \
    --color 'hl:-1:underline,hl+:-1:underline:reverse' \
    --delimiter ':' \
    --preview "bat --color=always {1} --theme='gruvbox-dark' --highlight-line {2}" \
    --preview-window 'up,60%,border-bottom,+{2}+3/3,~3')


    file=${result%%:*}
    line=$(echo "${result}" | cut -d: -f2)

    if [[ -n "$file" ]]; then
      nvim +"${line}" "$file"
    fi
}

main "$@"