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