provide-module local-kakrc %— declare-option str local_kakrc_trusted %exp{%val{config}/local_kakrc_trusted.txt} # ensures that the file exists define-command -hidden local-kakrc-ensure-file %{ nop %sh{ if [ ! -f "$kak_opt_local_kakrc_trusted" ]; then mkdir -p "$kak_opt_local_kakrc_trusted" touch "$kak_opt_local_kakrc_trusted" fi } } define-command local-kakrc-load-if-trusted %{ # first we check if the .kakrc exists evaluate-commands %sh{ if [ -f .kakrc ]; then if grep -qFx "$PWD" "$kak_opt_local_kakrc_trusted"; then echo "source .kakrc" else echo "info -title 'local-kakrc' 'Local .kakrc found, but directory is untrusted.'" fi fi } } define-command -params 0..1 local-kakrc-add-trusted %{ evaluate-commands %sh{ if [ "$#" -eq 0 ]; then arg="$PWD" else arg="$(realpath "$1")" fi echo "local-kakrc-ensure-file">"$kak_command_fifo" printf 'info -title "local-kakrc" "Adding %s to trusted"' "$arg" printf '%s\n' "$arg">>"$kak_opt_local_kakrc_trusted" } } define-command -params 0..1 local-kakrc-rm-trusted %{ evaluate-commands %sh{ if [ "$#" -eq 0 ]; then arg="$PWD" else arg="$(realpath "$1")" fi if [ ! -f "$kak_opt_local_kakrc_trusted" ]; then echo "fail local_kakrc_trusted not found!" exit 1 fi temp="$(mktemp)" touch "$temp" # check if path is in file if grep -qFx "$arg" "$kak_opt_local_kakrc_trusted"; then # perform removal grep -vxF "$arg" "$kak_opt_local_kakrc_trusted" >"$temp" mv -f "$temp" "$kak_opt_local_kakrc_trusted" else echo "info -title 'local-kakrc' 'No such trusted directory!'" rm "$temp" 2>/dev/null fi } } complete-command local-kakrc-rm-trusted shell-script-candidates %{ cat "$kak_opt_local_kakrc_trusted" } complete-command local-kakrc-add-trusted shell-script-candidates %{ fd -td --exclude '.git' --base-directory "$PWD" . } # syntax highlighting hook global BufCreate (.*/)?(\.kakrc) %{ set-option buffer filetype kak } —