Update emacs-bookmark.zsh
This commit is contained in:
parent
b39f4ce968
commit
f22d24b042
@ -67,13 +67,18 @@ function __bm_update_bookmark_list {
|
||||
done
|
||||
}
|
||||
function __bm_bookmark_location {
|
||||
local parts=(${(s:/:)"${1}"})
|
||||
local bm_name="${parts[1]}"
|
||||
local rest_arr=(${parts:1})
|
||||
local rest="${(j:/:)rest_arr}"
|
||||
for ((i = 1; i < ${#__bm_bookmark_cache}; i+=4)); do
|
||||
if [[ "${1}" = "${__bm_bookmark_cache[${i}]}" ]]; then
|
||||
printf '%s\n%d\n' "${__bm_bookmark_cache[${i} + 2]}" \
|
||||
"${__bm_bookmark_cache[${i} + 3]}"
|
||||
if [[ "${bm_name}" = "${__bm_bookmark_cache[${i}]}" ]]; then
|
||||
printf '%s\n%d\n%s\n' "${__bm_bookmark_cache[${i} + 2]}" \
|
||||
"${__bm_bookmark_cache[${i} + 3]}" "${rest}"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
printf '%s\n' "${bm_name}"
|
||||
return 1
|
||||
}
|
||||
function __bm_list_bookmarks {
|
||||
@ -104,16 +109,25 @@ function bm {
|
||||
local loc=(${(f)"$(__bm_bookmark_location "${1}")"})
|
||||
if [[ -d "${loc[1]}" ]]; then
|
||||
cd "${loc[1]}"
|
||||
if ! [[ -z "${loc[3]}" ]]; then
|
||||
if ! [[ -d "${loc[3]}" ]]; then
|
||||
cd - >/dev/null
|
||||
printf 'Bookmark exists, but trailing path doesn''t: "%s"\n' \
|
||||
"${loc[3]}"
|
||||
return 1
|
||||
fi
|
||||
cd "${loc[3]}"
|
||||
fi
|
||||
[[ "${BM_CWD_LS}" = '1' ]] && ls || true
|
||||
elif [[ -e "${loc[1]}" ]]; then
|
||||
${=EDITOR} "${loc[1]}"
|
||||
else
|
||||
printf 'No such bookmark: "%s"\n' "${1}"
|
||||
printf 'No such bookmark: "%s"\n' "${loc[1]}"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
function _bm {
|
||||
_arguments ':bookmark:_bookmarks'
|
||||
_arguments '1::bookmark:_bookmarks'
|
||||
}
|
||||
compdef _bm bm
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user