From f467caf42f87e1270d5bc5a3530ee66c12e2ae81 Mon Sep 17 00:00:00 2001 From: Caleb Heuer Date: Fri, 16 Jun 2023 17:42:04 -0600 Subject: Save and restore harpoons by PWD and git branch Fixes #2 --- README.md | 1 - harpoon.kak | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 921fdf9..26ef5d9 100644 --- a/README.md +++ b/README.md @@ -36,4 +36,3 @@ If the default bindings do not work for you, here are the relevant commands to c ## Roadmap - Save line and column information -- Persist harpoons per-session diff --git a/harpoon.kak b/harpoon.kak index 534e269..bd0ca90 100644 --- a/harpoon.kak +++ b/harpoon.kak @@ -83,3 +83,28 @@ hook global BufCreate \*harpoon\* %{ alias buffer w harpoon-update-from-list add-highlighter buffer/harpoon-indices regex ^\d: 0:function } + +# State saving - save by PWD and git branch, if any + +declare-option str harpoon_state_file %sh{ + git_branch=$(git -C "${kak_buffile%/*}" rev-parse --abbrev-ref HEAD 2>/dev/null) + state_file=$(printf "%s" "$PWD-$git_branch" | sed -e 's|_|__|g' -e 's|/|_-|g') + state_dir=${XDG_STATE_HOME:-~/.local/state}/kak/harpoon + mkdir -p $state_dir + echo $state_dir/$state_file +} + +hook global KakBegin .* %{ + evaluate-commands %sh{ + if [ -f "$kak_opt_harpoon_state_file" ]; then + printf "set-option global harpoon_files " + cat "$kak_opt_harpoon_state_file" + fi + } +} + +hook global KakEnd .* %{ + evaluate-commands %sh{ + printf "$kak_quoted_opt_harpoon_files" > "$kak_opt_harpoon_state_file" + } +} -- cgit v1.2.3