-
Notifications
You must be signed in to change notification settings - Fork 4
/
kamp-buffers
executable file
·44 lines (37 loc) · 995 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
36
37
38
39
40
41
42
43
44
#!/bin/sh
#
# pick buffers
#
# requires:
# - fzf (https://github.com/junegunn/fzf)
# - bat (https://github.com/sharkdp/bat)
set -euf
usage() {
printf "Usage: %s: [-s session]\n" "$(basename "$0")" >&2
exit 2
}
while getopts 's:h' OPTION; do
case $OPTION in
s)
session="$OPTARG"
;;
h|?)
usage
;;
esac
done
shift $((OPTIND - 1))
: ${session:=$KAKOUNE_SESSION}
if kamp ctx -c >/dev/null 2>/dev/null; then
exec_cmd="kamp -s $session send buffer {}"
else
exec_cmd="kamp -s $session attach -b {}"
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)"