#Shell scripts

1 messages · Page 1 of 1 (latest)

vagrant sable
#

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
brave edge
#

Using an active git repo as an application seems... unwise??

#

what's going on

vagrant sable
#

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

brave edge
#

I see

ember hearth
#

maybe a comment string in the beginning on its purpose would be beneficial

vagrant sable
#

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.

vagrant sable
brave edge
#

you have done this before lol

cerulean lily
#

Why would you want to have multiple views of the same? Or what is exactly a session?

brave edge
#

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."

ember hearth
#

probably a lang server among else?

vagrant sable
#

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

cerulean lily
#

So it's like having multiple editors opened in VSCode.

brave edge
#

Reminds me of this emacs(?)-like editor I used to use. Could have as many panes as one wanted.

vagrant sable