#!/usr/bin/env sh

query="${*:-}"
# query="$(echo "$@" | tr '[:upper:]' '[:lower:]')"

# choice="$(rg -il "$1" | fzf --exit-0 --select-1 --ansi --preview="bat {} | rg --color=always $1 --context 3" --preview-window=60%)"
choice=$(rg --smart-case --files-with-matches "${query}" | fzf --exit-0 --select-1 --ansi --preview="bat {} | rg ${query} --context 3" --preview-window=nohidden)

if [ -n "${choice}" ];then
  ${EDITOR:-vim} "+/\v${query}" "${choice}"
  # ${EDITOR:-vim}  "+/$1" "${choice}"
fi
