Remove bookmark.zsh
This commit is contained in:
parent
db347d3f5c
commit
06c33df30d
73
bookmark.zsh
73
bookmark.zsh
@ -1,73 +0,0 @@
|
|||||||
# A simple bookmark system
|
|
||||||
# $ZSH_BOOKMARK_DIR must be defined
|
|
||||||
|
|
||||||
# Create bookmark directory if it does not exist
|
|
||||||
[ ! -d "${ZSH_BOOKMARK_DIR}" ] && mkdir -p "${ZSH_BOOKMARK_DIR}"
|
|
||||||
function __zsh_list_bookmarks {
|
|
||||||
/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 {
|
|
||||||
# With no args, list all bookmarks
|
|
||||||
[ "${#}" -eq 0 ] && { __zsh_list_bookmarks; return }
|
|
||||||
# Otherwise, goto the bookmark in argv[1]
|
|
||||||
__zsh_check_bookmark_name "${1}" || { echo "No such bookmark: '${1}'!"; return 1 }
|
|
||||||
[ -L "${ZSH_BOOKMARK_DIR}/${1}" ] || { echo "No such bookmark: '${1}'!"; return 1 }
|
|
||||||
[ -e "${ZSH_BOOKMARK_DIR}/${1}" ] || { echo "The bookmark '${1}' refers to a non-existant file!"; return 1 }
|
|
||||||
cd -P "${ZSH_BOOKMARK_DIR}/${1}"
|
|
||||||
[[ -v ZSH_BOOKMARK_LS ]] && [[ "${ZSH_BOOKMARK_LS}" = 'true' ]] && ls
|
|
||||||
}
|
|
||||||
function _bm {
|
|
||||||
_arguments '::bookmark:_bookmarks'
|
|
||||||
}
|
|
||||||
compdef _bm bm
|
|
||||||
|
|
||||||
# bmadd [name] [dir]
|
|
||||||
function bmadd {
|
|
||||||
# With no args, add pwd
|
|
||||||
[ "${#}" -eq 0 ] && { bmadd "$(basename "${PWD}")" "${PWD}"; return }
|
|
||||||
# With one arg, add pwd as argv[1]
|
|
||||||
[ "${#}" -eq 1 ] && { bmadd "${1}" "${PWD}"; return }
|
|
||||||
local real_path="$(realpath "${2}")"
|
|
||||||
local bm_name="${1}"
|
|
||||||
__zsh_check_bookmark_name "${bm_name}" || { echo "Invalid bookmark: '${1}'!"; return 1 }
|
|
||||||
if [ -L "${ZSH_BOOKMARK_DIR}/${bm_name}" ]; then
|
|
||||||
echo "A bookmark with the name '${bm_name}' already exists!"
|
|
||||||
local reply
|
|
||||||
read -q 'reply?Overwrite? [y/N] '
|
|
||||||
printf '\n'
|
|
||||||
[[ "${reply}" =~ '[yY]' ]] || return 1
|
|
||||||
fi
|
|
||||||
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 {
|
|
||||||
[ "${#}" -eq 0 ] && { echo "usage: bmrm <name>"; return 1 }
|
|
||||||
__zsh_check_bookmark_name "${1}" || { echo "No bookmark with the name '${1}' exists!"; return 1 }
|
|
||||||
[ -L "${ZSH_BOOKMARK_DIR}/${1}" ] || { echo "No bookmark with the name '${1}' exists!"; return 1 }
|
|
||||||
local reply
|
|
||||||
read -q 'reply?Really delete? [y/N] '
|
|
||||||
printf '\n'
|
|
||||||
[[ "${reply}" =~ '[yY]' ]] || return 1
|
|
||||||
/bin/rm "${ZSH_BOOKMARK_DIR}/${1}"
|
|
||||||
echo "Deleted bookmark '${1}'"
|
|
||||||
}
|
|
||||||
function _bmrm {
|
|
||||||
_arguments ':bookmark:_bookmarks'
|
|
||||||
}
|
|
||||||
compdef _bmrm bmrm
|
|
3
init.zsh
3
init.zsh
@ -241,9 +241,6 @@ if cmd_exists direnv; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Bookmarks
|
# Bookmarks
|
||||||
# [ -v ZSH_BOOKMARK_DIR ] || ZSH_BOOKMARK_DIR="${HOME}/.cache/zsh/bookmarks"
|
|
||||||
# [ -v ZSH_BOOKMARK_LS ] || ZSH_BOOKMARK_LS=true
|
|
||||||
# source "${ZSH_CONFIG_DIR}/bookmark.zsh"
|
|
||||||
[[ -v BM_MODE ]] || BM_CWD_LS=1
|
[[ -v BM_MODE ]] || BM_CWD_LS=1
|
||||||
[[ -v BM_MODE ]] || BM_MODE=daemon
|
[[ -v BM_MODE ]] || BM_MODE=daemon
|
||||||
source "${ZSH_CONFIG_DIR}/emacs-bookmark.zsh"
|
source "${ZSH_CONFIG_DIR}/emacs-bookmark.zsh"
|
||||||
|
Loading…
Reference in New Issue
Block a user