AutoYADM commit: 2025-05-19 17:57:38
This commit is contained in:
parent
d9fb3ba788
commit
a2f513b31d
1 changed files with 82 additions and 45 deletions
|
@ -17,8 +17,45 @@ function kak-session -w kak --description "kakoune where sessions are derived fr
|
||||||
set git_dir (git -C (dirname $files[1]) rev-parse --show-toplevel 2>/dev/null)
|
set git_dir (git -C (dirname $files[1]) rev-parse --show-toplevel 2>/dev/null)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function fdup
|
||||||
|
set target $argv[1]
|
||||||
|
set dir (path dirname (pwd))
|
||||||
|
if test -n "$argv[2]"
|
||||||
|
set dir (path dirname "$argv[2]")
|
||||||
|
end
|
||||||
|
while test "$dir" != /
|
||||||
|
set result (fd --max-depth 1 -H -I -t f "$target" "$dir")
|
||||||
|
if test -n "$result"
|
||||||
|
echo (path dirname $result)
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
set dir (path dirname $dir)
|
||||||
|
end
|
||||||
|
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
set kakroot (fdup .kakroot $files[1])
|
||||||
|
|
||||||
|
if test -n "$kakroot"
|
||||||
|
set session_id (echo -n "$(path basename "$kakroot")" | tr --complement '[:alpha:]_-' '-')
|
||||||
|
# if there is no existing session
|
||||||
|
if not command kak -l | rg -xqF "$session_id"
|
||||||
|
set fifo_dir (mktemp -d --suffix=kak-init.XXXXXX)
|
||||||
|
set fifo "$fifo_dir/fifo"
|
||||||
|
mkfifo "$fifo"
|
||||||
|
|
||||||
|
setsid kak -d -s "$session_id" -E "cd %[$kakroot]; echo -to-file $fifo ready" &
|
||||||
|
|
||||||
|
# once $fifo has data, the kakoune server has initialized.
|
||||||
|
cat $fifo >/dev/null
|
||||||
|
|
||||||
|
command rm -r "$fifo_dir"
|
||||||
|
end
|
||||||
|
|
||||||
|
command kak -c "$session_id" $flags $files
|
||||||
|
else if [ -n "$git_dir" ]
|
||||||
# when in a git directory, share sessions
|
# when in a git directory, share sessions
|
||||||
if [ -n "$git_dir" ]
|
|
||||||
# the shared session id is {repo}__{branch} where repo is the remote repo name
|
# the shared session id is {repo}__{branch} where repo is the remote repo name
|
||||||
# or the basename of the git directory.
|
# or the basename of the git directory.
|
||||||
if set remote (git -C $git_dir remote get-url origin 2>/dev/null)
|
if set remote (git -C $git_dir remote get-url origin 2>/dev/null)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue