summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTill Höppner2018-04-22 11:07:47 +0200
committerTill Höppner2018-04-22 11:07:47 +0200
commitbfa28ccb68905df92d04e3056c6e7ecb7cc94b96 (patch)
tree0a3577243bcb35d8ca832b4d4b44160ca02c4b82
parent764e5d64de8a960b2d362b918937ff1c14aa3613 (diff)
downloadzsh-bfa28ccb68905df92d04e3056c6e7ecb7cc94b96.tar.gz
zsh-bfa28ccb68905df92d04e3056c6e7ecb7cc94b96.tar.xz
zsh-bfa28ccb68905df92d04e3056c6e7ecb7cc94b96.zip
Add bookmarking functions
-rw-r--r--conf.d/99-bookmarks.zsh54
1 files changed, 54 insertions, 0 deletions
diff --git a/conf.d/99-bookmarks.zsh b/conf.d/99-bookmarks.zsh
new file mode 100644
index 0000000..58bd29a
--- /dev/null
+++ b/conf.d/99-bookmarks.zsh
@@ -0,0 +1,54 @@
+export MARKPATH=$HOME/.local/zsh/marks
+mkdir -p "$MARKPATH"
+
+j() {
+ cd -P "$MARKPATH/$1" 2>/dev/null || { echo "No such mark: $1"; return 1 }
+}
+
+mc() {
+ if [[ ( $# == 0 ) || ( "$1" == "." ) ]]; then
+ MARK=$(basename "$PWD")
+ else
+ MARK="$1"
+ fi
+ if read -q \?"Mark $PWD as ${MARK}? (y/n) "; then
+ mkdir -p "$MARKPATH"; ln -s "$PWD" "$MARKPATH/$MARK"
+ fi
+}
+
+md() {
+ rm -i "$MARKPATH/$1"
+}
+
+ml() {
+ for link in $MARKPATH/*(@); do
+ local markname="$fg[cyan]${link:t}$reset_color"
+ local markpath="$fg[blue]$(readlink $link)$reset_color"
+ printf "%s\t" $markname
+ printf "-> %s \t\n" $markpath
+ done
+}
+
+ms() {
+ j $(ml | fzf --ansi | awk '{print $1}')
+}
+
+_completemarks() {
+ if [[ $(ls "${MARKPATH}" | wc -l) -gt 1 ]]; then
+ reply=($(ls $MARKPATH/**/*(-) | grep : | sed -E 's/(.*)\/([_a-zA-Z0-9\.\-]*):$/\2/g'))
+ else
+ if readlink -e "${MARKPATH}"/* &>/dev/null; then
+ reply=($(ls "${MARKPATH}"))
+ fi
+ fi
+}
+compctl -K _completemarks j
+compctl -K _completemarks um
+
+_mark_expansion() {
+ setopt extendedglob
+ autoload -U modify-current-argument
+ modify-current-argument '$(readlink "$MARKPATH/$ARG")'
+}
+zle -N _mark_expansion
+bindkey "^g" _mark_expansion