define-command load -params 2 %{ try %{ source "%val{config}/%arg{1}/%arg{2}.kak" echo -debug "Loaded %arg{1}/%arg{2}.kak" } catch %{ echo -debug "Couldn't load %arg{1}/%arg{2}: %val{error}" } } define-command -docstring %{ loadg : source a .kak config file, with glob support (spawns subshell) } loadg -params 2 %{ try %{ evaluate-commands %sh{ for f in $kak_config/$1/$2.kak; do printf 'source %s\necho -debug "Loaded %s"\n' "$f" "${f#$kak_config/}" done } } catch %{ echo -debug "Couldn't loadg %arg{1}/%arg{2}: %val{error}" } } complete-command loadg shell-script %{ case "$kak_token_to_complete" in 0) find "$kak_config" -maxdepth 1 -mindepth 1 -name .git -prune -o -name "$1*" -type d -print | sed "s|^$kak_config/||" ;; 1) find "$kak_config/$1" -mindepth 1 -name .git -prune -o -name "$2*.kak" -type f -print | sed "s|^$kak_config/$1/||" | sed 's/.kak$//' ;; esac } complete-command load shell-script %{ case "$kak_token_to_complete" in 0) find "$kak_config" -maxdepth 1 -mindepth 1 -name .git -prune -o -name "$1*" -type d -print | sed "s|^$kak_config/||" ;; 1) find "$kak_config/$1" -mindepth 1 -name .git -prune -o -name "$2*.kak" -type f -print | sed "s|^$kak_config/$1/||" | sed 's/.kak$//' ;; esac } declare-option -hidden str-to-str-map load_defer define-command -docstring %{ loadd-register : register the key to load the .kak file at } -params 2 loadd-register %{ set-option -add global load_defer "%arg{1}=%arg{2}" echo -debug "Registered key %arg{1} to load file %arg{2}" } define-command -docstring %{ loadd : if the name has been registered with loadd-register, load that file now } -params 1 loadd %{ evaluate-commands %sh{ target="$1" eval set -- "$kak_quoted_opt_load_defer" loaded=false while [ $# -gt 0 ]; do key=${1%%=*} val=${1#*=} if [ "$target" = "$key" ]; then loaded=true printf 'source %s\n' "$val" break fi shift done if [ $loaded = false ]; then printf 'fail "%s"\n' "Couldn't load $target: not in the map" fi } echo -debug "Deferred load of key %arg{1}" } hook global ModuleLoaded kak %{ add-highlighter shared/kakrc/code/load regex (?:\s|\A)\Kload[gd]?(?:(?=\s)|\z) 0:keyword }