Skip to content

Commit 785614c

Browse files
add search word in directory and open in nvim
1 parent 5d81afc commit 785614c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

OS/Linux/Bash/scripts/search

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
# 1. Search for text in files using Ripgrep
4+
# 2. Interactively restart Ripgrep with reload action
5+
# 3. Open the file in nvim
6+
7+
# after chmod +x this files, move it to /usr/bin and call it by its name anywhere
8+
9+
RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
10+
INITIAL_QUERY="${*:-}"
11+
IFS=: read -ra selected < <(
12+
FZF_DEFAULT_COMMAND="$RG_PREFIX $(printf %q "$INITIAL_QUERY")" \
13+
fzf --ansi \
14+
--disabled --query "$INITIAL_QUERY" \
15+
--bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \
16+
--delimiter : \
17+
--preview 'bat --color=always {1} --highlight-line {2}' \
18+
--preview-window right
19+
)
20+
[ -n "${selected[0]}" ] && nvim "${selected[0]}"
21+
# 'up,60%,border-bottom,+{2}+3/3,~3'

0 commit comments

Comments
 (0)