--- /dev/null
+#!/bin/sh
+#
+# pick buffers
+#
+# requires:
+# - fzf (https://github.com/junegunn/fzf)
+# - bat (change to your liking) (https://github.com/sharkdp/bat)
+
+preview_cmd="bat --color=always --line-range=:500"
+history_file="$HOME/.cache/kks-buffers-history"
+
+[ -f "$history_file" ] || touch "$history_file"
+
+kks get '%val{buflist}' |
+ grep -F "$*" |
+ fzf --height 100% --layout reverse --style full --prompt 'buf> ' --preview "kks cat -b {} | $preview_cmd" \
+ --header="[c-x] delete, [c-t] new scratch" \
+ --bind="ctrl-x:execute-silent(kks send -b {} delete-buffer)+reload(kks get '%val{buflist}')" \
+ --bind="ctrl-t:execute-silent(kks send edit -scratch {q})+reload(kks get '%val{buflist}')" \
+ --history="$history_file" |
+ while read -r name; do
+ kks send buffer "$name"
+ done
--- /dev/null
+#!/bin/sh
+#
+# pipe stdin into Kakoune fifo buffer
+#
+# Example:
+# make | kks-fifo
+set -euf
+
+# Fail early if no session in context
+kks env >/dev/null 2>&1 || {
+ # show error
+ kks env
+ exit 1
+}
+
+tmp=$(mktemp -d "${TMPDIR:-/tmp}"/kks-fifo.XXXXXXXX)
+fifo="$tmp/fifo"
+
+cleanup() {
+ rm -r "$tmp"
+}
+
+trap 'cleanup; trap - EXIT' EXIT INT HUP
+mkfifo "$fifo"
+kks send edit! -fifo "$fifo" '*fifo*'
+cat >"$fifo"
--- /dev/null
+#!/bin/sh
+#
+# pick files
+#
+# requires:
+# - fd (https://github.com/sharkdp/fd)
+# - fzf (https://github.com/junegunn/fzf)
+# - bat (change to your liking) (https://github.com/sharkdp/bat)
+
+preview_cmd="bat --color=always --line-range=:500"
+history_file="$HOME/.cache/kks-files-history"
+
+[ -f "$history_file" ] || touch "$history_file"
+
+fd --type file . "$@" |
+ fzf --multi --height 100% --style full --prompt 'files> ' \
+ --preview "$preview_cmd {}" --history="$history_file" |
+ while read -r file; do
+ kks edit "$file"
+ done
--- /dev/null
+#!/bin/sh
+#
+# pick filetype from Kakoune's runtime dir and set in current buffer
+#
+# requires:
+# - fzf (https://github.com/junegunn/fzf)
+
+ft_dir="$(kks get %val[runtime])/rc/filetype"
+
+find "$ft_dir"/*.kak -type f -exec basename -s .kak {} \; |
+ fzf --height 100% --style full --prompt 'filetypes> ' |
+ xargs -I {} kks send 'set buffer filetype {}'
--- /dev/null
+#!/bin/sh
+#
+# pick files from git ls-files
+#
+# requires:
+# - fzf (https://github.com/junegunn/fzf)
+# - bat (change to your liking) (https://github.com/sharkdp/bat)
+
+preview_cmd="bat --color=always --line-range=:500"
+history_file="$HOME/.cache/kks-files-history"
+
+[ -f "$history_file" ] || touch "$history_file"
+
+git ls-files --full-name "$(git rev-parse --show-toplevel)" "$@" |
+ fzf --multi --height 100% --style full --prompt 'files> ' \
+ --preview "$preview_cmd {}" --history="$history_file" |
+ while read -r file; do
+ kks edit "$file"
+ done
--- /dev/null
+#!/bin/sh
+#
+# search for pattern in workdir
+#
+# requires:
+# - ripgrep (https://github.com/BurntSushi/ripgrep)
+# - fzf (https://github.com/junegunn/fzf)
+# - bat (change to your liking) (https://github.com/sharkdp/bat)
+
+history_file="$HOME/.cache/kks-grep-history"
+query=""
+
+[ -f "$history_file" ] || touch "$history_file"
+[ "$(kks get %val[selection_length])" -gt 1 ] && query="$(kks get %val[selection])"
+
+rg --vimgrep '.+' "$@" |
+ SHELL=sh fzf --delimiter=":" --query="$query" --height="100%" --prompt="grep> " --history="$history_file" \
+ --preview='range="$(echo {2}-5 | bc | sed "s/^-.*/0/"):$(echo {2}+20 | bc)"; bat -r "$range" -n --color always -H {2} {1}' |
+ awk -F':' '{print $1 " " "+" $2 ":" $3 }' |
+ xargs -r kks edit
--- /dev/null
+#!/bin/sh
+#
+# open lf in single-pane view with current buffer selected
+#
+# requires:
+# - lf (https://github.com/gokcehan/lf)
+
+kks get '%val{buffile}' |
+ xargs -I {} lf -command "set nopreview; set ratios 1" {}
--- /dev/null
+#!/bin/sh
+#
+# jump to line in buffer
+#
+# requires:
+# - fzf (https://github.com/junegunn/fzf)
+
+kks cat |
+ nl -ba -w4 -s' │ ' |
+ fzf --height 100% --style full --prompt 'lines> ' |
+ awk '{print $1}' |
+ xargs -r -I {} kks send "execute-keys '<esc>{}gx'"
--- /dev/null
+#!/bin/sh
+#
+# jump to heading in markdown file
+#
+# requires:
+# - ripgrep (https://github.com/BurntSushi/ripgrep)
+# - fzf (https://github.com/junegunn/fzf)
+
+kks cat |
+ rg -n '^#+' |
+ column -t -s ':' |
+ fzf --height 100% --style full --prompt 'heading> ' |
+ awk '{print $1}' |
+ xargs -r -I {} kks send "execute-keys '<esc>{}gx'"
--- /dev/null
+#!/bin/sh
+#
+# pick recent file
+#
+# requires:
+# - fzf (https://github.com/junegunn/fzf)
+# - bat (change to your liking) (https://github.com/sharkdp/bat)
+#
+# for this to work, add the following in kakrc:
+# (requires sponge from moreutils: https://joeyh.name/code/moreutils/)
+# hook global BufCreate [^*].* %{
+# nop %sh{
+# mru=~/.cache/kak-mru
+# echo "$kak_buffile" | awk '!seen[$0]++' - "$mru" | sponge "$mru"
+# }
+# }
+
+preview_cmd="bat --color=always --line-range=:500"
+
+(fzf --height 100% --prompt 'mru> ' --style full --preview "$preview_cmd {}" |
+ xargs -r kks edit) < ~/.cache/kak-mru
--- /dev/null
+#!/bin/sh
+#
+# select kak session and client to set environment
+# use as `eval $(kks-select)`, eg: `alias ks="eval $(kks-select)"` in shell config
+#
+# requires:
+# - fzf (https://github.com/junegunn/fzf)
+
+command kak -clear
+
+kks list |
+ fzf -d '\t*: *' --style full \
+ --header="[c-x] kill, [c-t] new, [c-r] reload" \
+ --bind="ctrl-x:execute-silent(kks kill -s {1})+reload(sleep 0.1; kks list)" \
+ --bind="ctrl-t:execute-silent(kks new {q})+reload(sleep 0.1; kks list)" \
+ --bind="ctrl-r:reload(kks list)" \
+ --preview-window=down:0% --preview="kks send -a info; kks send -s {1} -c {2} info -markup '{2}@{+b}[{1}]'" |
+ awk -F '\t*: *' '{print "export KKS_SESSION=" $1 "; export KKS_CLIENT=" $2}'