Overhaul bookmark.zsh completions
This commit is contained in:
parent
3d25e8136c
commit
29fb2c96d0
19
bookmark.zsh
19
bookmark.zsh
@ -4,11 +4,16 @@
|
||||
# Create bookmark directory if it does not exist
|
||||
[ ! -d "${ZSH_BOOKMARK_DIR}" ] && mkdir -p "${ZSH_BOOKMARK_DIR}"
|
||||
function __zsh_list_bookmarks {
|
||||
command ls "${ZSH_BOOKMARK_DIR}"
|
||||
/bin/ls "${ZSH_BOOKMARK_DIR}"
|
||||
}
|
||||
function __zsh_check_bookmark_name {
|
||||
! [[ "${1}" == *'/'* ]]
|
||||
}
|
||||
function _bookmarks {
|
||||
for file in "${ZSH_BOOKMARK_DIR}/"*; do
|
||||
compadd "${file#"${ZSH_BOOKMARK_DIR}/"}"
|
||||
done
|
||||
}
|
||||
|
||||
# bm <bookmark>
|
||||
function bm {
|
||||
@ -22,9 +27,7 @@ function bm {
|
||||
[[ -v ZSH_BOOKMARK_LS ]] && "${ZSH_BOOKMARK_LS}" && ls
|
||||
}
|
||||
function _bm {
|
||||
for file in "${ZSH_BOOKMARK_DIR}/"*; do
|
||||
compadd "$(basename "${file}")"
|
||||
done
|
||||
_arguments '::bookmark:_bookmarks'
|
||||
}
|
||||
compdef _bm bm
|
||||
|
||||
@ -47,6 +50,10 @@ function bmadd {
|
||||
ln -nfs "${real_path}" "${ZSH_BOOKMARK_DIR}/${bm_name}"
|
||||
echo "Created bookmark '${bm_name}'"
|
||||
}
|
||||
function _bmadd {
|
||||
_arguments ':name' '::directory:_directories'
|
||||
}
|
||||
compdef _bmadd bmadd
|
||||
|
||||
# bmrm <name>
|
||||
function bmrm {
|
||||
@ -57,10 +64,10 @@ function bmrm {
|
||||
read -q 'reply?Really delete? [y/N] '
|
||||
printf '\n'
|
||||
[[ "${reply}" =~ '[yY]' ]] || return 1
|
||||
command rm "${ZSH_BOOKMARK_DIR}/${1}"
|
||||
/bin/rm "${ZSH_BOOKMARK_DIR}/${1}"
|
||||
echo "Deleted bookmark '${1}'"
|
||||
}
|
||||
function _bmrm {
|
||||
_bm
|
||||
_arguments ':bookmark:_bookmarks'
|
||||
}
|
||||
compdef _bmrm bmrm
|
||||
|
Loading…
x
Reference in New Issue
Block a user