DEV Community

Cover image for Terminal Tricks: Directory Bookmarks
Aly Sivji
Aly Sivji

Posted on • Originally published at alysivji.github.io

Terminal Tricks: Directory Bookmarks

This post was originally published on Siv Scripts

Even though my development folders are well organized, I still have to feel my way around the filesystem when I'm looking for a project directory. It's like trying to find a lightswitch in a dark room: a cd here, an ls there, maybe a find when I'm stuck.

I always get to where I want to go, but not without some frustration along the way. Plus, all the seconds spent navigating directories starts to add up.

Wait a minute. I use bookmarks in my browser, so why am I not using them in my shell?

A quick Google search led me to Bashmarks. Absolute game changer. I can move around the filesystem with ease.

Feel a bit like Dr. Who.

Teleport like a boss

In this Quick Hit, we will explore Bashmarks, walk through the installation process, and get a feel of the most commonly used commands.


Bashmarks

Bashmarks is a [bash] shell script that allows you to save and jump to commonly used directories

It supports tab completion (!!!) and has a very simple interface with only 5 commands to memorize.

Use another shell? Not a problem. There are ports of bashmarks for fish and zsh.

Installation

Download the files into a temporary directory and install using GNU make:

mkdir temp && cd temp
git clone git://github.com/huyng/bashmarks.git
cd bashmarks
make install
echo "source ~/.local/bin/bashmarks.sh" >> ~/.bash_profile
source ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

And we're good to go!

Commands

s <bookmark_name> - Saves the current directory as "bookmark_name"
g <bookmark_name> - Goes (cd) to the directory associated with "bookmark_name"
p <bookmark_name> - Prints the directory associated with "bookmark_name"
d <bookmark_name> - Deletes the bookmark
l                 - Lists all available bookmarks
Enter fullscreen mode Exit fullscreen mode

We can save bookmarks using the s [bookmark_name] command:

Create bashmark

List all bashmarks with l:

List bashmarks

Navigate to project directory using g [bookmark_name]:

Jump to bashmark


Conclusion

Bashmarks is a tool that increases developer productivity.

Do you have an interesting terminal workflow or trick to share? Please comment below!

Top comments (8)

Collapse
 
vitalybe profile image
Vitaly

I recommend to use "fasd" instead. It removes the whole need to manually enter bookmarks and automatically remembers every folder your interacted. So you just need to "cd temp" once and since then, just type "z temp" to go there.

I wrote about it here: hackernoon.com/macbook-my-command-...

Collapse
 
infomiho profile image
Mihovil Ilakovac

I would also like to recommend a tool called wd. It basically does the same thing but for me the way it operates it's a little bit explicit. For example the adding of new path is wd add and it adds the current working directory.

github.com/mfaerevaag/wd/blob/mast...

Collapse
 
lucretius profile image
Robert Lippens

Interesting - I always accomplished this by just adding a bunch of aliases to my bash profile (cdw for example just cd's into my workspace. This seems like a cleaner way to handle things when you've got a bunch of places to go!

Collapse
 
fenetikm profile image
Michael Welford • Edited

I know this is old but for anyone stumbling across this and they are using zsh then what you really want is to use hash to modify the command hash table so that you can then get an even shorter syntax and not need the extra aliases. E.g. if you run this:

hash -d o=~/Downloads/

you can then do:

$ cd ~o

or even:

$ ~o

or even even:

$ o

to change directory. You can also then substitute in ~o anywhere where you would usually place a path such as ls ~0.

Collapse
 
elisarver profile image
Eli Sarver • Edited

z is also good. It keeps a list of your statistically frequent and recent cd commands. If you have a lot of directories with similar names, however, you'll probably have better luck with this approach.

The one thing I take issue with in this approach is the use of four single-letter shortcuts. For me, g is for git, and l is for ls -la.

It's weird for me to take issue with this approach this way, since I do use the z macro.

Collapse
 
dwisatriow profile image
Dwi Satrio W. • Edited

I have installed it and it looks really helpful. But, can anyone tell me how to turn off sort of command auto completion on terminal, like when I type "l" it always treat the command as "ls", so I can't list all my bookmarks.

Collapse
 
orangecc1530 profile image
橙橙橙子

interesting~

Collapse
 
psnebc profile image
Patrick Schanen

I have installed this