Skip to content

zsh and bash plugin to bookmark directories to cd. This is a fork with added functionality!

License

Notifications You must be signed in to change notification settings

erikw/cd-bookmark

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cd-bookmark

OSS Lifecycle License

FORK

This is a maintained fork of mollifier/cd-bookmark that adds the following features:

Migrating from bashmarks? Then the following aliases will make you feel at home:

alias g='cd-bookmark -c'
alias s='cd-bookmark -a'
alias l='cd-bookmark -l'
alias e='cd-bookmark -e'
alias p='cd-bookmark -p'
alias d='cd-bookmark -d'

Fork maintainance notes:

$ git rebase -ir upstream/master

Synopsis

zsh and bash 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.

How to set up

Manually install

Put cd-bookmark and _cd-bookmark files somewhere in your $fpath and add the following line to your .zshrc:

autoload -Uz cd-bookmark

For example

# download all files
% cd /path/to/dir
% git clone https://github.com/erikw/cd-bookmark.git

And add the following lines to your .zshrc:

fpath=(/path/to/dir/cd-bookmark(N-/) $fpath)

autoload -Uz cd-bookmark

Installing using Antigen

If you use Antigen, add the following line to your .zshrc:

antigen bundle erikw/cd-bookmark

You can set alias to this function. e.g.

alias cdb='cd-bookmark'

Bash

For bash users, put this in your shell initialization file (typically $HOME/.bashrc):

source path/to/dir/cd-bookmark/cd-bookmark

Usage

# 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.

Options

  • -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
  • -d BOOKMARK_ID delete 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

Variables

The location of the bookmarks list file depends on the envionment's configuration. The file is searched in the following order:

  1. $CD_BOOKMARK_FILE - if it is set. This has highest precedence. Thus you can set this to override to custom location.
  2. $XDG_CONFIG_HOME/cd-bookmarks/bookmarks - if the directory cd-bookmarks/ exist. Note that $XDG_CONFIG_HOME defaults to $HOME/.config
  3. $HOME/.cdbookmark - fall back to old default $HOME/.cdbookmark

Examples

# 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.

# To delete a bookmark, run cd-bookmark with -d option.
% cd-bookmark -d work

About

zsh and bash plugin to bookmark directories to cd. This is a fork with added functionality!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 100.0%