diff options
| author | Caleb Heuer <ch@raiguard.me> | 2023-06-16 17:42:04 -0600 |
|---|---|---|
| committer | Caleb Heuer <ch@raiguard.me> | 2023-06-16 17:42:04 -0600 |
| commit | f467caf42f87e1270d5bc5a3530ee66c12e2ae81 (patch) | |
| tree | fb56b39a1b560f29641d7569fdca74584f7b8d6f | |
| parent | e7d7ec1535f67a1cbfb94f5a6ca2a407c3bf759d (diff) | |
Save and restore harpoons by PWD and git branch
Fixes #2
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | harpoon.kak | 25 |
2 files changed, 25 insertions, 1 deletions
@@ -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" + } +} |
