May 15, 2019

No more cd ../../

Certain tools and frameworks dictate that you work in deeply-nested folder hierarchies. Ansible, used for provisioning and deployment, is one such tool. Here’s the tree output of a very simple — almost toyish — Ansible project I’ve been playing with:

├── hosts
├── playbook.yml
└── roles
    └── setup
        ├── files
        ├── tasks
        │   ├── apps.yml
        │   ├── main.yml
        │   └── terminal.yml
        └── vars
            └── main.yml
5 directories, 7 files

One of the first Terminal commands one learns is how to navigate to a child directory, or traverse several ones deep. For example, if I’m in the folder ansible-macos-setup and I want to go to straight to tasks, I can do this:

$ cd roles/setup/tasks

But now what if I’m in the tasks folder and want to go back to ansible-macos-setup? It’s easy. That is, if I remember I’m 3 directories down:

$ cd ../../../

Except I’m lazier than that. Constantly navigating with multiple ../ and remembering where I am exactly in the hierarchy is a pain.

After some Googling I’ve found cds missing sister, aptly called bd”1. With bd, if you’re in: ~/src/org/main/site/utils/file/reader/misc, you can simply type this in the Terminal to go to the site folder:

$ bd site

Better yet, one can write the first few letters (bd si) of a parent directory and bd will navigate to the closest match. If more than one parent directory is a match, the closest in the hierarchy is chosen.

There’s additional functionality documented in the project’s Github repository, alongside installation instructions.

  1. for back directory” I guess.

Previous post
A more Pythonic dictionary Dictionaries are versatile, fast, and efficient. This post will cover two dictionary related features that I feel don’t get enough attention: and .
Next post
Django tutorial: as-you-type search with Ajax This one is going to be a walkthrough tutorial on how to implement what’s defined as “incremental search” in a Django app. We want results