Update emacs-bookmark.zsh

This commit is contained in:
Alexander Rosenberg 2024-08-20 00:37:48 -04:00
parent f22d24b042
commit 9b90c216f3
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730

View File

@ -2,6 +2,7 @@
# Enable color utilities
autoload colors && colors
autoload regexp-replace
__bm_bookmark_cache=()
@ -97,7 +98,7 @@ function __bm_list_bookmarks {
function _bookmarks {
for ((i = 1; i < ${#__bm_bookmark_cache}; i+=4)); do
compadd "${__bm_bookmark_cache[${i}]}"
compadd -S '/' "${__bm_bookmark_cache[${i}]}"
done
}
@ -127,7 +128,28 @@ function bm {
fi
}
function _bm {
_arguments '1::bookmark:_bookmarks'
local arg="${words[${CURRENT}]}"
if ! [[ "${arg}" == */* ]]; then
_arguments '1::bookmark:_bookmarks'
else
local loc=(${(f)"$(__bm_bookmark_location "${arg}")"})
if [[ -d "${loc[1]}" ]]; then
local parts=(${(s:/:)loc[3]})
local bm="${${(s:/:)${arg}}[1]}"
local subdir="${(j:/:)parts[1,${#parts}-1]}"
local search="${parts[${#parts}]}"
if ((${#parts} > 0)) && [[ "${arg}" == */ ]]; then
subdir="${subdir}/${search}"
subdir="${subdir#/}"
search=""
fi
for file in "${loc[1]}/${subdir}/${search}"*(/); do
local clean_file="${bm}/${file#"${loc[1]}"}"
regexp-replace clean_file '/+' '/'
compadd -U -S '/' "${clean_file}"
done
fi
fi
}
compdef _bm bm