forked from vbauerster/kamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kamp-buffers
executable file
·35 lines (30 loc) · 916 Bytes
/
kamp-buffers
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
#!/bin/sh
#
# pick buffers
#
# requires:
# - fzf (https://github.com/junegunn/fzf)
# - bat (https://github.com/sharkdp/bat)
#
# optional param: $1 = attach
# optional param: $2 = session
set -euf
session=""
exec_cmd=""
if [ $# -eq 0 ]; then
session="$KAKOUNE_SESSION"
exec_cmd="kamp -s $session -c ${KAKOUNE_CLIENT:-client0} send buffer {}"
elif [ "$1" = "attach" ]; then
session="${2:-$KAKOUNE_SESSION}"
exec_cmd="kamp -s $session attach -b {}"
else
exit 1
fi
buffers_cmd="kamp -s $session get -b \* val -s bufname"
preview_cmd="kamp -s $session cat -b {} | bat --color=always --line-range=:500 --file-name {}"
delete_cmd="kamp -s $session send -b {} delete-buffer"
eval "$buffers_cmd" |
fzf --prompt 'buf> ' --preview "$preview_cmd" \
--header '[c-x] delete' \
--bind "ctrl-x:execute-silent($delete_cmd)+reload($buffers_cmd)" \
--bind "enter:become($exec_cmd)"