← blog

Shell Bookmarks

ascii art that reads shell bookmarks

I'm always trying to improve my work flow by automating processes. I even developed a workshop about Automating Mindfully where I discussed my coding process and introduced Bash scripting. I had an afternoon today where I had some time to revisit an old bash function I wrote to flesh out a shell bookmarking program.

I'm always juggling multiple projects at once and I've taken to meticulously organizing my file system. While my file system is more organize, I've done it by deeply nesting my folders. Because of these two things, I have to switch directories often and traverse many folders to get there. I had looked into bookmarks for the shell before but I haven't found one that fit my workflow quite right, although I was impressed by huyng/bashmarks. I wanted to take some of his ideas and incorporate them into a more personalized application.

My code can be found on github and I want to explain a little more about my design process and neat things I learned while making the script.

I guess I should start out with what I wasn't so excited with about Bashmarks to explain some of my own objectives for my application. First, I wasn't so enthused by how Bashmarks creates several Bash functions. While it is clear what each function does when reading it, I don't think in use having single-letter functions is the most clear syntax. In addition I have some aliases set up which conflict with Bashmark's naming scheme. To solve this I created a single function which then checks following arguments to decide what to do next. This way all the bookmark script is rolled into one function for easy access.

Another major divergence from Bashmark is the lack of naming for my bookmarks. Bashmarks has a very robust bookmarking system where you can tag directories with a bookmark name. But for me I wanted to make a quick and simple system for tagging directories you are currently working on. This way there isn't really a need to remember the name you saved your bookmark as and you can regularly dump your bookmarks file when you aren't working on a directory. #no hoarding

When clearing your bookmarksfile it will keep a backup of your most recent bookmarks which you can reload by changing the .shellbookmarks.bak to .shellbookmarks. I've also included some shortcuts if you want to omit the bmk command arguments. For example bmk 0 will equal bmk g 0 and bmk will resolve as bmk l

The major functionality of my applications are:

# bookmarks are saved to $HOME/.shellbookmarks

bmk s - Saves the current location to your bookmarks
bmk l - Lists bookmarked location
bmk g <bookmark number> - Jump to bookmarked location
bmk d <bookmark number> - Deletes bookmarked location
bmk clear - Deletes all bookmarks

Extras:
bmk <bookmark number> - Jumps to bookmarked location if exists
bmk <invalid argument> - Lists valid commands
bmk (no args) - Defaults to list bookmarks

I find having a simplified bookmarking system quite useful and it was enjoyable to make. Enjoy!