-
Notifications
You must be signed in to change notification settings - Fork 31
/
fzbuku
executable file
·51 lines (44 loc) · 938 Bytes
/
fzbuku
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
#!/usr/bin/env bash
_video() {
x-terminal-emulator -t mpv -e "mpv '$1'"
}
export -f _video
_open() {
case $1 in
*youtube.com*) _video "$1" ;;
*youtu.be*) _video "$1" ;;
*vimeo.com*) _video "$1" ;;
*) x-www-browser "$1" ;;
esac
}
export -f _open
printf -v jq '.[] | "\(.index) \(.uri) %s\(.tags)%s \(.title)"' "$(tput setaf 7)" "$(tput sgr0)"
main() {
local choice=()
mapfile -t choice < <(buku -p -j |
jq -r "$jq" |
SHELL=bash fzf \
--ansi \
--tac \
--bind='enter:execute: _open {2}' \
--expect='ctrl-d,ctrl-e' \
--delimiter=' ' \
--height=100% \
--no-hscroll \
--preview-window=down \
--preview='buku -p {1}; w3m {2}' \
--query="$*" \
--with-nth=3..)
selection=${choice[@]:1}
case ${choice[0]} in
ctrl-d)
buku -d ${selection[0]%% *}
main
;;
ctrl-e)
buku -w ${selection[0]%% *}
main
;;
esac
}
main "$*"