Created
June 9, 2020 09:36
-
-
Save mzanibelli/5c68edb5b518dd6a94b488e2fc1d572c to your computer and use it in GitHub Desktop.
Persistent Kakoune session based on git
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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