-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrg_
executable file
·65 lines (53 loc) · 1.67 KB
/
rg_
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
## By Davoud Arsalani
## https://github.com/davoudarsalani/scripts
## https://github.com/davoudarsalani/scripts/blob/master/rg_
## https://raw.githubusercontent.com/davoudarsalani/scripts/master/rg_
## https://davoudarsalani.ir
## https://github.com/junegunn/fzf/wiki/Examples
source "$HOME"/main/scripts/gb
source "$HOME"/main/scripts/gb-color
title="${0##*/}"
function display_help {
source "$HOME"/main/scripts/.help
r_help
}
function get_opt {
local options
options="$(getopt --longoptions 'help,directory:' --options 'hd:' --alternative -- "$@")"
eval set -- "$options"
while true; do
case "$1" in
-h|--help )
display_help ;;
-d|--directory )
shift
directory="$1" ;;
-- )
break ;;
esac
shift
done
}
get_opt "$@"
heading "$title"
[ "$directory" ] || {
directory="$(select_directory)" 2>/dev/null || exit 37
}
cd "$directory" || exit ## TODO find how to pass $directory to RG in JUMP_1 instead of cding
main_item="$(pipe_to_fzf 'all' 'bash' 'python' 'html' "header=rg in ${PWD/$HOME/\~}")" && wrap_fzf_choice "$main_item" || exit 37
case "$main_item" in
bash )
RG+=' --type-not py' ;;
python )
RG+=' --type py' ;;
html )
RG+=' --type html' ;;
esac
## JUMP_1
INITIAL_QUERY=''
eval "$RG '$INITIAL_QUERY'" | sed "s#$HOME#~#" | \
fzf --preview 'eval "$HIGHLIGHT" {-1} 2>/dev/null | \
eval "\rg $RG_MATCH_FLAGS" {q} 2>/dev/null' \
--header "rg in ${PWD/$HOME/\~}" \
--bind "Return:reload:$RG {q} || true" --phony --query "$INITIAL_QUERY"