#!/bin/sh
#
# version 2: Use ripgrep to find files (much better)
# has ability to parse glob and use pcre regex
# function RG() { zrgu "$@" }


# ripgrep
if command -v rg >/dev/null 2>&1; then
  alias RGG='zrgu -g "*.go"'              # interactive; go
  alias RGJ='RG -g "*.{js,jsx,json}"'    # interactive; javascript
  # alias RGL='RG -g "*.lua"'              # lua files only (interactively)
  # alias RGN='RG -g "*.{lua,vim}"'        # lua + vim files only (interactively)
  alias RGP='zrgu -g "*.py"'              # interactive; python
  alias RGR='RG -g "*.rs"'               # interactively; rust
  alias RGV='zrgu -g "*.vim"'             # interactive; vim
  alias RGZ='zrgu -g "*.zsh"'             # interactive; zsh

  alias prg='parallel"" -X rg'

  alias pcrg="rg --pcre2"                # pcre
  alias frg="rg --files-with-matches"    # filenames only
  alias lrg="rg -F"                      # fixed-strings
  alias irg="rg --no-ignore"             # no ignore

  # -v, -i, -z, -F most commonly-used rg options.
  alias rgv='rg -v'

  # alias rga="rg --hidden --ignore-vcs '--glob=!.git/*'"

  # unrestricted.
  # alias rgu='rg -u'
  alias rguv='rg -uv'
  # search everything ripgrep can. anything more than this calls for ripgrep-all
  alias rguu='rg -zuuu'
  # just find all instances of this string. dont be clever.
  # might crash with big binary files
  # alias rguf='rg -auuuF'

  # zip
  # alias rgz='rg -z'
  alias rgzv='rg -zv'

  alias rgd='rg-delta'
  alias rgz='f-rg'
fi
alias vgoall='v $(ls **/*.go | one_line)'
alias vpyall='v $(ls **/*.py | one_line)'

# function zeee() {
#   in-dir "${ZDOTDIR}/" zrgu "$@"
# }

# keybinding

# rg {{{

# RG with $BUFFER
function :RG-buffer() {
  zmodload -Fa zsh/parameter p:functions
  eval "() { $functions[RG] } $BUFFER"
  zle reset-prompt
}; zle -N :RG-buffer
# Zkeymaps+=('C-x C-u' :RG-buffer)
bindkey '^X^u' :RG-buffer

zle -N efwiki
zle -N efzsh
zle -N efvim

# }}}


