this repo has no description
at main 53 lines 1.7 kB view raw
1# -*- sh -*- 2 3# Handle bookmarks. This uses the static named directories feature of 4# zsh. Such directories are declared with `hash -d 5# name=directory`. Both prompt expansion and completion know how to 6# handle them. We populate the hash with directories. 7# 8# With autocd, you can just type `~-bookmark`. Since this can be 9# cumbersome to type, you can also type `@@` and this will be turned 10# into `~-` by ZLE. 11 12# Manage bookmarks 13bookmark() { 14 local link 15 [[ -d $MARKPATH ]] || mkdir -p $MARKPATH 16 if (( $# == 0 )); then 17 # When no arguments are provided, just display existing 18 # bookmarks 19 for link in $MARKPATH/*(-N/); do 20 local markname=${(%):-%F{green}${link:t}%f} 21 local markpath=${(%):-%F{blue}${link:A}%f} 22 printf "%-30s → %s\n" $markname $markpath 23 done 24 else 25 # Otherwise, we may want to add a bookmark or delete an 26 # existing one. 27 local -a delete 28 zparseopts -D d=delete 29 if (( $+delete[1] )); then 30 # With `-d`, we delete an existing bookmark 31 command rm $MARKPATH/$1 32 else 33 # Otherwise, add a bookmark to the current 34 # directory. The first argument is the bookmark 35 # name. `.` is special and means the bookmark should 36 # be named after the current directory. 37 local name=$1 38 [[ $name == "." ]] && name=${PWD:t} 39 ln -sf $PWD $MARKPATH/$name 40 hash -d -- ${name}=${PWD} 41 fi 42 fi 43} 44 45bookmarks_setup () { 46 # Populate the hash 47 local link 48 for link ($MARKPATH/*(-N/)) { 49 hash -d -- ${link:t}=${link:A} 50 } 51} 52 53bookmarks_setup "$@"