Update emacs-bookmark.zsh

This commit is contained in:
Alexander Rosenberg 2024-08-27 18:36:33 -07:00
parent 9abe05ccfe
commit 38f0a9fc2b
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730

View File

@ -29,6 +29,18 @@ function __bm_find_user_emacs_dir {
} }
BM_BOOKMARK_PATH="${BM_BOOKMARK_PATH:-"$(__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 { function __bm_update_bookmark_list {
local quoted_output local quoted_output
__bm_last_read_time="${EPOCHSECONDS}" __bm_last_read_time="${EPOCHSECONDS}"
@ -70,6 +82,7 @@ function __bm_update_bookmark_list {
for entry in ${quoted_output}; do for entry in ${quoted_output}; do
__bm_bookmark_cache+="${(Q)entry}" __bm_bookmark_cache+="${(Q)entry}"
done done
__bm_hash_dirs
} }
function __bm_bookmark_location { function __bm_bookmark_location {
local parts=(${(s:/:)"${1}"}) local parts=(${(s:/:)"${1}"})
@ -103,7 +116,7 @@ function __bm_list_bookmarks {
function _bookmarks { function _bookmarks {
for ((i = 1; i < ${#__bm_bookmark_cache}; i+=4)); do for ((i = 1; i < ${#__bm_bookmark_cache}; i+=4)); do
compadd -q -S '/' "${__bm_bookmark_cache[${i}]}" compadd -q "${__bm_bookmark_cache[${i}]}"
done done
} }
@ -134,7 +147,9 @@ function bm {
function _bm { function _bm {
local arg="${(Q)words[${CURRENT}]}" local arg="${(Q)words[${CURRENT}]}"
if ! [[ "${arg}" == */* ]]; then 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 else
__bm_bookmark_location "${arg}" __bm_bookmark_location "${arg}"
if [[ -d "${__bm_res[1]}" ]]; then if [[ -d "${__bm_res[1]}" ]]; then
@ -246,12 +261,14 @@ function _bmrm {
} }
compdef _bmrm bmrm compdef _bmrm bmrm
function __bm_auto_reload_hook { function __bm_precmd_hook {
# Auto reload
if (( "${BM_AUTO_RELOAD:-0}" )) && if (( "${BM_AUTO_RELOAD:-0}" )) &&
(( ${__bm_last_read_time} < "$(zstat +mtime "${BM_BOOKMARK_PATH}")" )); then (( ${__bm_last_read_time} < "$(zstat +mtime "${BM_BOOKMARK_PATH}")" )); then
__bm_update_bookmark_list __bm_update_bookmark_list
fi 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 __bm_update_bookmark_list