#Shell scripts
1 messages · Page 1 of 1 (latest)
For example, this script would have been more annoying to write in Lua than shell:
#!/bin/sh
kak="/usr/bin/kak"
# Only do stuff if invoked with 'kak <filename>'
case "$1" in
-*)
$kak $@
exit
;;
esac
basedir=$(git rev-parse --show-toplevel 2> /dev/null)
if [ -n "$basedir" ]; then
# Set session name
session=$(basename "$basedir" | sed "s/\./-/g")
# Change filename to absolute path
# This only works with the first one, but that's fine
set -- $(realpath $1)
# Change to project root dir
cd $basedir
fi
sessions=$($kak -l)
if $(echo "$sessions" | grep -q "(dead)"); then
echo "Clearing dead sessions"
$kak -clear
sessions=$($kak -l)
fi
# TODO: Convenient way to connect to last session?
if [ -z "$session" ]; then
$kak $@
exit
fi
if $(echo "$sessions" | grep -q "\b$session\b"); then
$kak -c $session $@
else
$kak -s $session $@
fi
That's not what this is doing. This sets the kakoune session name to the name of the git repo that I opened it in if there is one
It also automatically clears dead kakoune sessions if there are any
I see
maybe a comment string in the beginning on its purpose would be beneficial
What this lets me do is have kak open, then open another terminal and open kak from there and it'll connect to the same session instead of creating a new one. I do that a lot.
Perhaps, but this is a personal script in my dotfiles so it doesn't necessarily need to be documented well
you have done this before lol
Why would you want to have multiple views of the same? Or what is exactly a session?
I have at least two or three images about such things... "I'll remember what everything means and how it works. No one else would ever work on it. Comments are unnecessary. Exceptions are obvious."
probably a lang server among else?
Kakoune uses a client-server architecture. When you're using the editor you use the client, but all of the actual logic happens on the server. You can connect multiple clients to the same server to get multiple windows for the same editing session. Kakoune doesn't have any built-in windowing logic on its own.
For instance, these are two different terminal windows and two different invocations of kak, but they're in the same session so they share registers, an LSP session, settings, etc
So it's like having multiple editors opened in VSCode.
Reminds me of this emacs(?)-like editor I used to use. Could have as many panes as one wanted.
Precisely, but this relies on your window manager to do windowing instead of building it into the editor. It's a double-edged sword.