-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsuper-shift-r
executable file
·36 lines (26 loc) · 1.08 KB
/
super-shift-r
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
#!/usr/bin/env bash
set -o nounset
cd ~/wiki || exit
generate_search_command() {
printf '%s | %s | %s' \
"rg --count-matches --smart-case $1" \
"LC_ALL=C sort -t: -k2rn" \
"sed -E 's/\.(md|txt):/:/; s/:1$/ (1 match)/; s/:([0-9]+)$/ (\1 matches)/'"
}
FZF_DEFAULT_COMMAND=$(generate_search_command \'\')
printf -v FZF_DEFAULT_OPTS '%s%q %s %s %s' \
"--expect ctrl-/ --disabled --bind change:reload:" "$(generate_search_command '{q}')" \
"--color dark,hl:cyan:regular,fg+:white:regular,hl+:cyan:regular:reverse" \
"--color query:white:regular,info:gray:regular,prompt:cyan:regular,pointer:cyan:bold" \
"--color spinner:black:regular --prompt='~ ' ${FZF_DEFAULT_OPTS:-}"
export FZF_DEFAULT_COMMAND FZF_DEFAULT_OPTS
# shellcheck disable=SC2016
readarray -t fzf_output < <(
xterm -name 'floating xterm' -geometry 36x24 -e 'fzf > /proc/$PPID/fd/1')
(( ${#fzf_output[@]} == 2 )) || exit
key=${fzf_output[0]}
page=${fzf_output[1]%% *}
url=https://wiki.meribold.eu/
[[ $key == ctrl-/ ]] && url+=edit/
url+=$page
$FIREFOX "$url" && i3-msg '[class="^firefox-esr$"] focus'