Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Persistent Kakoune session based on git
#!/bin/sh
change_dir() {
printf 'change-directory "%s"' "$1"
}
start_session() {
session="$1"
shift
if kak -l | grep -wq "$session"; then
return
fi
kak -d -s "$session" "$@"
}
start_git() {
toplevel="$1"
shift
session="$(echo "$toplevel" | md5sum | cut -d ' ' -f 1)"
start_session "$session" -E "$(change_dir "$toplevel")"
kak -c "$session" "$@"
}
start_main() {
if [ "$#" -eq 0 ]; then
kak -c main -e "$(change_dir "$PWD")"
else
kak -c main "$@"
fi
}
main() {
toplevel="$(git rev-parse --show-toplevel 2>/dev/null)"
if [ -z "$toplevel" ]; then
start_main "$@"
else
start_git "$toplevel" "$@"
fi
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.