From 9b90c216f38c95b0a3a74444c70f2da772d2021f Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Tue, 20 Aug 2024 00:37:48 -0400 Subject: [PATCH] Update emacs-bookmark.zsh --- emacs-bookmark.zsh | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/emacs-bookmark.zsh b/emacs-bookmark.zsh index db5c0e7..d058bb4 100644 --- a/emacs-bookmark.zsh +++ b/emacs-bookmark.zsh @@ -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