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