AutoYADM commit: 2025-07-18 17:19:43

This commit is contained in:
Daniel Fichtinger 2025-07-18 17:19:43 -04:00
parent 8f2f9512e7
commit 5e68dc889e
2 changed files with 28 additions and 19 deletions

View file

@ -0,0 +1,10 @@
provide-module local-kakrc %—
# syntax highlighting
hook global BufCreate (.*/)?\.kakrc %{
set-option buffer filetype kak
}
# load proj. config
define-command root-load-kakrc %{
try %{ source %exp{%opt{root_path}/.kakrc} }
}

View file

@ -1,5 +1,5 @@
provide-module root %∴
declare-option str-list root_globs .git .kakrc kakrc
declare-option str-list root_globs .kakrc kakrc .git
declare-option str root_path %sh{ echo "$PWD" }
declare-option -hidden str root_prev_pwd %opt{root_path}
# recursively discovers the root dir based on root_globs
@ -10,39 +10,33 @@ provide-module root %∴
root="$dir"
while [ "$dir" != "/" ]; do
for glob in $globs; do
match=$(fd -H -td -1 --glob "$glob" "$dir" --max-depth 1 2>/dev/null | head -n1)
if [ -n "$match" ]; then
root="$(dirname "$match")"
break
fi
done
dir="$(dirname "$dir")"
for glob in $globs; do
match=$(fd -H -td -1 --glob "$glob" "$dir" --max-depth 1 2>/dev/null | head -n1)
if [ -n "$match" ]; then
root="$(dirname "$match")"
break
fi
done
dir="$(dirname "$dir")"
done
printf 'set-option global root_path "%s"\n' "$root"
printf 'echo "Discovered root: %s"\n' "$root"
}
}
# project-specific configuration
hook global BufCreate (.*/)?(\.kakrc\.local|\.kakrc\.local|\.kakrc) %{
set-option buffer filetype kak
}
define-command root-load-kakrc %{
try %{ source .kakrc } catch %{
try %{ source .kakrc.local } catch %{ try %{ source .local.kakrc } }
}
}
# change the cwd to root
define-command -hidden root-cd-root-impl %{
set-option global root_prev_pwd %sh{ echo "$PWD" }
change-directory %opt{root_path}
echo "CWD: %opt{root_path}"
}
# change cwd back to what it was before
define-command -hidden root-cd-return-impl %{
change-directory %opt{root_prev_pwd}
echo "CWD: %opt{root_prev_pwd}"
}
# toggle between root and previous cwd
define-command root-cd %{
evaluate-commands %sh{
if [ "$PWD" != "$kak_opt_root_path" ]; then
@ -53,11 +47,16 @@ provide-module root %∴
}
}
# edit a file, relative to root
define-command -params 1 root-edit %{
edit %exp{%opt{root_path}/%arg{1}}
}
complete-command root-edit shell-script-candidates %{
fd -H -tf --exclude '.git' --base-directory "$kak_opt_root_path" .
}
alias global root root-discover
alias global re root-edit
alias global rc root-cd