From 38f0a9fc2bc09899fbbc4a80ce8cf6700a1faed6 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Tue, 27 Aug 2024 18:36:33 -0700 Subject: [PATCH] Update emacs-bookmark.zsh --- emacs-bookmark.zsh | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/emacs-bookmark.zsh b/emacs-bookmark.zsh index e9ccacc..36f71a7 100644 --- a/emacs-bookmark.zsh +++ b/emacs-bookmark.zsh @@ -29,6 +29,18 @@ function __bm_find_user_emacs_dir { } BM_BOOKMARK_PATH="${BM_BOOKMARK_PATH:-"$(__bm_find_user_emacs_dir)"}" + +function __bm_hash_dirs { + # First empty the hash table + hash -dr + + # Then add the hash dirs + for ((i = 1; i < ${#__bm_bookmark_cache}; i+=4)); do + local name="${__bm_bookmark_cache[${i}]://=/}" + hash -d "${name}=${__bm_bookmark_cache[${i} + 2]}" + done +} + function __bm_update_bookmark_list { local quoted_output __bm_last_read_time="${EPOCHSECONDS}" @@ -70,6 +82,7 @@ function __bm_update_bookmark_list { for entry in ${quoted_output}; do __bm_bookmark_cache+="${(Q)entry}" done + __bm_hash_dirs } function __bm_bookmark_location { local parts=(${(s:/:)"${1}"}) @@ -103,7 +116,7 @@ function __bm_list_bookmarks { function _bookmarks { for ((i = 1; i < ${#__bm_bookmark_cache}; i+=4)); do - compadd -q -S '/' "${__bm_bookmark_cache[${i}]}" + compadd -q "${__bm_bookmark_cache[${i}]}" done } @@ -134,7 +147,9 @@ function bm { function _bm { local arg="${(Q)words[${CURRENT}]}" if ! [[ "${arg}" == */* ]]; then - _arguments '1::bookmark:_bookmarks' + for ((i = 1; i < ${#__bm_bookmark_cache}; i+=4)); do + compadd -q -S '/' "${__bm_bookmark_cache[${i}]}" + done else __bm_bookmark_location "${arg}" if [[ -d "${__bm_res[1]}" ]]; then @@ -246,12 +261,14 @@ function _bmrm { } compdef _bmrm bmrm -function __bm_auto_reload_hook { +function __bm_precmd_hook { + # Auto reload if (( "${BM_AUTO_RELOAD:-0}" )) && (( ${__bm_last_read_time} < "$(zstat +mtime "${BM_BOOKMARK_PATH}")" )); then __bm_update_bookmark_list fi } -(( ${precmd_functions[(I)__bm_auto_reload_hook]} )) || precmd_functions+=(__bm_auto_reload_hook) +(( ${precmd_functions[(I)__bm_precmd_hook]} )) || + precmd_functions+=(__bm_precmd_hook) __bm_update_bookmark_list