No more cd ../../
May 15, 2019Certain 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:
ansible-macos-setup
├── 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 cd
’s 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.
for “back directory” I guess.↩︎