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