One of my most used features of zsh is named directories. I keep my dotfiles synced across multiple machines via Dropbox (referral link) and a Makefile that creates symlinks automagically.
My named directories start with ~ for my home directory so they need to exist for expansion to work properly and not output errors when I log in. When I first implemented syncing I added this check with a very simple test:
1
| |
One line like this isn’t too bad but when you have 30, it gets a little silly looking.
I finally took the time to sit down and read the docs on zsh associative arrays and whipped up a much better solution.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |
The unset isn’t necessary here for the base functionality. I had another problem. With 30 or 40 named dirs, some belonging to projects that I might not have looked at in 6 months and suddenly need to come back to, it’s hard to remember the name I gave for a directory. I added an lsdirs function that lists just the named directories that existing on the machine I’m on.
1 2 3 4 5 6 | |
This gives me nice easy to read output with both the names and the full path.
This blog post is more future reference for myself but perhaps it may be useful to you.
For those interested, here is the Makefile I use:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |