Update emacs-bookmark.zsh
This commit is contained in:
parent
9b90c216f3
commit
7f7aa9def4
@ -5,6 +5,7 @@ autoload colors && colors
|
|||||||
autoload regexp-replace
|
autoload regexp-replace
|
||||||
|
|
||||||
__bm_bookmark_cache=()
|
__bm_bookmark_cache=()
|
||||||
|
local __bm_res=()
|
||||||
|
|
||||||
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" ]] &&
|
||||||
@ -74,12 +75,13 @@ function __bm_bookmark_location {
|
|||||||
local rest="${(j:/:)rest_arr}"
|
local rest="${(j:/:)rest_arr}"
|
||||||
for ((i = 1; i < ${#__bm_bookmark_cache}; i+=4)); do
|
for ((i = 1; i < ${#__bm_bookmark_cache}; i+=4)); do
|
||||||
if [[ "${bm_name}" = "${__bm_bookmark_cache[${i}]}" ]]; then
|
if [[ "${bm_name}" = "${__bm_bookmark_cache[${i}]}" ]]; then
|
||||||
printf '%s\n%d\n%s\n' "${__bm_bookmark_cache[${i} + 2]}" \
|
__bm_res=("${__bm_bookmark_cache[${i} + 2]}"
|
||||||
"${__bm_bookmark_cache[${i} + 3]}" "${rest}"
|
"${__bm_bookmark_cache[${i} + 3]}"
|
||||||
|
"${rest}")
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
printf '%s\n' "${bm_name}"
|
__bm_res=()
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
function __bm_list_bookmarks {
|
function __bm_list_bookmarks {
|
||||||
@ -98,7 +100,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 -S '/' "${__bm_bookmark_cache[${i}]}"
|
compadd -q -S '/' "${__bm_bookmark_cache[${i}]}"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,23 +109,22 @@ function bm {
|
|||||||
__bm_update_bookmark_list || \
|
__bm_update_bookmark_list || \
|
||||||
{ printf 'Updating bookmark list failed!\n'; return 1 }
|
{ printf 'Updating bookmark list failed!\n'; return 1 }
|
||||||
(( ${#} == 0 )) && { __bm_list_bookmarks; return }
|
(( ${#} == 0 )) && { __bm_list_bookmarks; return }
|
||||||
local loc=(${(f)"$(__bm_bookmark_location "${1}")"})
|
__bm_bookmark_location "${1}"
|
||||||
if [[ -d "${loc[1]}" ]]; then
|
local bm_loc="${__bm_res[1]}"
|
||||||
cd "${loc[1]}"
|
local target="${__bm_res[1]}/${__bm_res[3]}"
|
||||||
if ! [[ -z "${loc[3]}" ]]; then
|
if (( ${#__bm_res} != 0 )) && [[ -e "${bm_loc}" ]]; then
|
||||||
if ! [[ -d "${loc[3]}" ]]; then
|
if [[ -d "${target}" ]]; then
|
||||||
cd - >/dev/null
|
cd "${target}"
|
||||||
printf 'Bookmark exists, but trailing path doesn''t: "%s"\n' \
|
[[ "${BM_CWD_LS}" = '1' ]] && ls || true
|
||||||
"${loc[3]}"
|
elif [[ -e "${target}" ]]; then
|
||||||
return 1
|
${=EDITOR} "${target}"
|
||||||
fi
|
else
|
||||||
cd "${loc[3]}"
|
printf 'Bookmark exists, but trailing path doesn'"'"'t: "%s"\n' \
|
||||||
|
"${__bm_res[3]}"
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
[[ "${BM_CWD_LS}" = '1' ]] && ls || true
|
|
||||||
elif [[ -e "${loc[1]}" ]]; then
|
|
||||||
${=EDITOR} "${loc[1]}"
|
|
||||||
else
|
else
|
||||||
printf 'No such bookmark: "%s"\n' "${loc[1]}"
|
printf 'No such bookmark: "%s"\n' "${__bm_res[1]}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -132,9 +133,9 @@ function _bm {
|
|||||||
if ! [[ "${arg}" == */* ]]; then
|
if ! [[ "${arg}" == */* ]]; then
|
||||||
_arguments '1::bookmark:_bookmarks'
|
_arguments '1::bookmark:_bookmarks'
|
||||||
else
|
else
|
||||||
local loc=(${(f)"$(__bm_bookmark_location "${arg}")"})
|
__bm_bookmark_location "${arg}"
|
||||||
if [[ -d "${loc[1]}" ]]; then
|
if [[ -d "${__bm_res[1]}" ]]; then
|
||||||
local parts=(${(s:/:)loc[3]})
|
local parts=(${(s:/:)__bm_res[3]})
|
||||||
local bm="${${(s:/:)${arg}}[1]}"
|
local bm="${${(s:/:)${arg}}[1]}"
|
||||||
local subdir="${(j:/:)parts[1,${#parts}-1]}"
|
local subdir="${(j:/:)parts[1,${#parts}-1]}"
|
||||||
local search="${parts[${#parts}]}"
|
local search="${parts[${#parts}]}"
|
||||||
@ -143,11 +144,15 @@ function _bm {
|
|||||||
subdir="${subdir#/}"
|
subdir="${subdir#/}"
|
||||||
search=""
|
search=""
|
||||||
fi
|
fi
|
||||||
for file in "${loc[1]}/${subdir}/${search}"*(/); do
|
local pre_path="${__bm_res[1]}/${subdir}/"
|
||||||
local clean_file="${bm}/${file#"${loc[1]}"}"
|
local prefix="${bm}/${subdir}"
|
||||||
regexp-replace clean_file '/+' '/'
|
if ! [[ -z "${subdir}" ]]; then
|
||||||
compadd -U -S '/' "${clean_file}"
|
prefix+='/'
|
||||||
done
|
fi
|
||||||
|
compset -P "${(b)prefix}"
|
||||||
|
for file in "${pre_path}${search}"*; do
|
||||||
|
compadd -W "${pre_path}" -f "${file:t}"
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user