def find -docstring "find files" -menu -params 1 \ %{ edit -existing %arg{1} } \ -shell-script-candidates %{ fd -t f --hidden --color=never -E .git } def file-manager -params .. %{ terminal-singleton files env "DAFFM_PATH_RELATIVE_TO=%val{client_env_PWD}" daffm -c @kak %arg{@} } def findfzf -params .. %{ terminal-singleton fzf sh -c \ 'kcr edit $(fd -t f --hidden --color=never -E .git | \ fzf --prompt='':find '' --multi --min-height=100 \ --preview=''bat --color=always {}'' \ --bind ''ctrl-o:execute(kcr edit {})'' \ $@)' findfzf-cmd %arg{@} } def findfzf-filtered -params 1 %{ terminal-singleton fzf sh -c \ 'export pat=$1; kcr edit $(fd -t f --hidden --color=never -E .git | \ grep -E ''''$pat'''' | \ fzf --prompt='':find# '' --multi --min-height=100 \ --preview=''bat --color=always {}'' \ --info-command ''printf $pat'' \ )' findfzf-cmd %arg{1} } declare-user-mode file map global user f ': enter-user-mode file' -docstring 'File mode' map global file F ': find ' -docstring 'Find files' map global file n ': file-manager %val{buffile}' -docstring 'File manager' map global file f ': findfzf' -docstring 'Fzf' map global file ': findfzf -q %val{selection}' -docstring 'Fzf selection' declare-user-mode buffer map global user b ': enter-user-mode -count %val{count} buffer' -docstring 'Buffer mode' map global buffer b ': buffer ' -docstring 'Switch buffer' map global buffer ': buffer-jump %val{count}; buffers-show' -docstring 'Jump to buffer' map global buffer n ': buffer-next; buffers-show' -docstring 'Next buffer' map global buffer p ': buffer-previous; buffers-show' -docstring 'Previous buffer' map global buffer d ': delete-buffer; buffers-show' -docstring 'Delete buffer' map global buffer s ': write' -docstring 'Save' def buffers-show %{ info -title 'buffers' -markup %sh{ echo "$kak_quoted_buflist" | xargs -n1 | grep -v -E '^([*]debug[*])$' | while IFS= read buf; do if [ -z "$buf" ]; then echo "{comment}{Normal}" elif [ "$buf" == "$kak_bufname" ]; then echo "{keyword}$buf{Normal}" else echo "{Default}$buf{Normal}" fi done | nl -w 2 } } def buffer-jump -params 1 %{ evaluate-commands %sh{ if ! [ "$1" == "0" ]; then buf=$(echo "$kak_quoted_buflist" | xargs -n1 | grep -v -E '^([*]debug[*])$' | head -n "$1" | tail -n1) [ -z "$buf" ] || printf "buffer '%s'" $(echo "$buf" | sed "s/'/''/g") fi } }