summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaleb Heuer <ch@raiguard.me>2023-06-16 17:42:04 -0600
committerCaleb Heuer <ch@raiguard.me>2023-06-16 17:42:04 -0600
commitf467caf42f87e1270d5bc5a3530ee66c12e2ae81 (patch)
treefb56b39a1b560f29641d7569fdca74584f7b8d6f
parente7d7ec1535f67a1cbfb94f5a6ca2a407c3bf759d (diff)
Save and restore harpoons by PWD and git branch
Fixes #2
-rw-r--r--README.md1
-rw-r--r--harpoon.kak25
2 files changed, 25 insertions, 1 deletions
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"
+ }
+}