Add auto-updating of bookmarks
This commit is contained in:
parent
06c33df30d
commit
181dd2d533
@ -3,9 +3,12 @@
|
||||
# Enable color utilities
|
||||
autoload colors && colors
|
||||
autoload regexp-replace
|
||||
zmodload -F zsh/stat b:zstat
|
||||
zmodload zsh/datetime
|
||||
|
||||
__bm_bookmark_cache=()
|
||||
local __bm_bookmark_cache=()
|
||||
local __bm_res=()
|
||||
let __bm_last_read_time=-1
|
||||
|
||||
function __bm_find_user_emacs_dir {
|
||||
[[ -f "${HOME}/.emacs.d/var/bookmark-default.el" ]] &&
|
||||
@ -24,8 +27,11 @@ function __bm_find_user_emacs_dir {
|
||||
"daemon" or define $BM_BOOKMARK_PATH!\n'
|
||||
return 1
|
||||
}
|
||||
BM_BOOKMARK_PATH="${BM_BOOKMARK_PATH:-"$(__bm_find_user_emacs_dir)"}"
|
||||
|
||||
function __bm_update_bookmark_list {
|
||||
local quoted_output
|
||||
__bm_last_read_time="${EPOCHSECONDS}"
|
||||
case "${BM_MODE}" in
|
||||
'daemon')
|
||||
quoted_output=(${(z)${"$(command emacs -Q --batch --eval \
|
||||
@ -42,9 +48,6 @@ function __bm_update_bookmark_list {
|
||||
out))))))))")":1:-1}})
|
||||
;;
|
||||
''|'emacs')
|
||||
if ! [[ -v BM_BOOKMARK_PATH ]]; then
|
||||
local BM_BOOKMARK_PATH="$(__bm_find_user_emacs_dir)"
|
||||
fi
|
||||
quoted_output=(${(z)${"$(command emacs -Q --batch --eval \
|
||||
"(prin1
|
||||
(with-temp-buffer
|
||||
@ -115,7 +118,7 @@ function bm {
|
||||
if (( ${#__bm_res} != 0 )) && [[ -e "${bm_loc}" ]]; then
|
||||
if [[ -d "${target}" ]]; then
|
||||
cd "${target}"
|
||||
[[ "${BM_CWD_LS}" = '1' ]] && ls || true
|
||||
(( "${BM_CWD_LS:-0}" )) && ls || true
|
||||
elif [[ -e "${target}" ]]; then
|
||||
${=EDITOR} "${target}"
|
||||
else
|
||||
@ -241,4 +244,12 @@ function _bmrm {
|
||||
}
|
||||
compdef _bmrm bmrm
|
||||
|
||||
function __bm_auto_reload_hook {
|
||||
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)
|
||||
|
||||
__bm_update_bookmark_list
|
||||
|
Loading…
Reference in New Issue
Block a user