zsh plugin to bookmark directories to cd.
Inspired by mokemokechicken post and shell script in the post.
This plugin is forked from the script. The original script is licensed under the MIT License.
Put cd-bookmark and _cd-bookmark files somewhere in your $fpath and add the following line to your .zshrc:
autoload -Uz cd-bookmark
# download all files
% cd /path/to/dir
% git clone https://github.com/mollifier/cd-bookmark.git
And add the following lines to your .zshrc:
fpath=(/path/to/dir/cd-bookmark(N-/) $fpath)
autoload -Uz cd-bookmark
If you use Antigen, add the following line to your .zshrc:
antigen bundle mollifier/cd-bookmark
You can set alias to this function. e.g.
alias cdb='cd-bookmark'
# 1st form
% cd-bookmark -a [BOOKMARK_ID]
# or
# 2nd form
% cd-bookmark [-c] BOOKMARK_ID
# or
# 3rd form
% cd-bookmark [-l]
In the 1st form, add current directory to bookmark with BOOKMARK_ID. BOOKMARK_ID is used as a key in bookmark.
In the 2nd form, find directory by BOOKMARK_ID and change directory to it. In this form, you can add relative path from bookmark real path at the end of BOOKMARK_ID (see example below).
In the 3rd form, list current bookmark.
-a
[BOOKMARK_ID] add current directory to bookmark
with no BOOKMARK_ID, automatically use free ID number as BOOKMARK_ID-c
BOOKMARK_ID change directory which is identified by BOOKMARK_ID-l
list bookmark-e
edit bookmark file-p
BOOKMARK_ID display bookmark real path for BOOKMARK_ID-h
display this help and exit
Bookmark list are stored in ~/.cdbookmark
file. This file name can be changed by CD_BOOKMARK_FILE
variable.
# Current directory is '/home/mollifier/work'.
% pwd
/home/mollifier/work
# Add current directory to bookmark. It's bookmark ID is 'work'.
% cd-bookmark -a work
# cd somewhere.
% cd
# Back to 'work' directory.
% cd-bookmark work
% pwd
/home/mollifier/work
# Add another directory to bookmark.
% cd /home/mollifier/tmp
% cd-bookmark -a tmp
# To show current bookmark, run cd-bookmark without any options or with -l option.
% cd-bookmark
tmp|/home/mollifier/tmp
work|/home/mollifier/work
# You can add relative path from bookmark real path at the end of BOOKMARK_ID.
% cd-bookmark work/project/zsh
% pwd
/home/mollifier/work/project/zsh
# To edit bookmark, run cd-bookmark with -e option.
% cd-bookmark -e
# Open bookmark file with $EDITOR (vim, emacs, etc.), so you can edit bookmark.