z_mirror/dotfiles
git clone https://git.raiguard.me/z_mirror/dotfiles
b5eca58
noctalia
1define-command load -params 2 %{ 2 try %{ 3 source "%val{config}/%arg{1}/%arg{2}.kak" 4 echo -debug "Loaded %arg{1}/%arg{2}.kak" 5 } catch %{ 6 echo -debug "Couldn't load %arg{1}/%arg{2}: %val{error}" 7 } 8} 9define-command -docstring %{ 10 loadg <subdirdir> <file>: source a .kak config file, with glob support (spawns subshell) 11} loadg -params 2 %{ 12 try %{ 13 evaluate-commands %sh{ 14 for f in $kak_config/$1/$2.kak; do 15 printf 'source %s\necho -debug "Loaded %s"\n' "$f" "${f#$kak_config/}" 16 done 17 } 18 } catch %{ 19 echo -debug "Couldn't loadg %arg{1}/%arg{2}: %val{error}" 20 } 21} 22 23complete-command loadg shell-script %{ 24 case "$kak_token_to_complete" in 25 0) 26 find "$kak_config" -maxdepth 1 -mindepth 1 -name .git -prune -o -name "$1*" -type d -print | 27 sed "s|^$kak_config/||" 28 ;; 29 1) 30 find "$kak_config/$1" -mindepth 1 -name .git -prune -o -name "$2*.kak" -type f -print | 31 sed "s|^$kak_config/$1/||" | sed 's/.kak$//' 32 ;; 33 esac 34} 35 36complete-command load shell-script %{ 37 case "$kak_token_to_complete" in 38 0) 39 find "$kak_config" -maxdepth 1 -mindepth 1 -name .git -prune -o -name "$1*" -type d -print | 40 sed "s|^$kak_config/||" 41 ;; 42 1) 43 find "$kak_config/$1" -mindepth 1 -name .git -prune -o -name "$2*.kak" -type f -print | 44 sed "s|^$kak_config/$1/||" | sed 's/.kak$//' 45 ;; 46 esac 47} 48 49declare-option -hidden str-to-str-map load_defer 50 51define-command -docstring %{ 52 loadd-register <name> <path>: register the key <name> to load the .kak file at <path> 53} -params 2 loadd-register %{ 54 set-option -add global load_defer "%arg{1}=%arg{2}" 55 echo -debug "Registered key %arg{1} to load file %arg{2}" 56} 57 58define-command -docstring %{ 59 loadd <key>: if the name <key> has been registered with loadd-register, load that file now 60} -params 1 loadd %{ 61 evaluate-commands %sh{ 62 target="$1" 63 eval set -- "$kak_quoted_opt_load_defer" 64 loaded=false 65 while [ $# -gt 0 ]; do 66 key=${1%%=*} 67 val=${1#*=} 68 if [ "$target" = "$key" ]; then 69 loaded=true 70 printf 'source %s\n' "$val" 71 break 72 fi 73 shift 74 done 75 if [ $loaded = false ]; then 76 printf 'fail "%s"\n' "Couldn't load $target: not in the map" 77 fi 78 } 79 echo -debug "Deferred load of key %arg{1}" 80} 81 82hook global ModuleLoaded kak %{ 83 add-highlighter shared/kakrc/code/load regex (?:\s|\A)\Kload[gd]?(?:(?=\s)|\z) 0:keyword 84}