Skip to content

Instantly share code, notes, and snippets.

@mzanibelli
Created June 9, 2020 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzanibelli/5c68edb5b518dd6a94b488e2fc1d572c to your computer and use it in GitHub Desktop.
Save mzanibelli/5c68edb5b518dd6a94b488e2fc1d572c to your computer and use it in GitHub Desktop.
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