Terminal tricks
Since writing this page years ago, I've become a bit better at using the Terminal.1 I just realised how simple it is to move to a Johnny.Decimal folder. Here's how.
I'll explain why this works, as you'll need to tweak it for your own setup. So the first thing you need to know is where my system lives on my filesystem. My personal system, folder name P76 Johnny's personal system, is in my ~/Documents folder.
To make the examples here simpler I'll assume we've already cd ~/Documents.
Wildcards
Two quick things to know.
A wildcard * means 'any text'. So instead of P76 Johnny's personal system I can just write P76*. This works uniquely well in Johnny.Decimal because the majority of your folders start with a unique number.
You can expand this by using the amazingly-named globstar pattern. Within a path, ** will match any folder. It's like a really-wildcard.
Globs
Seriously, this pattern is called a glob. You weren't allowed to have those when I was at school.
If I want to navigate to my ID 15.53, this is what I do.
cd P76*/**/15.53*
That's it! We're saying please change directory to the folder that starts P76, of which there is only one. Then, search all of its subfolders **, until you find one that starts 15.53. There's only one of those.
Open the folder in Finder
If you want to actually open a Finder window, vs. staying in the Terminal:
open P76*/**/15.53*
Amaaaaazing.
Advanced script
How's this update to the cdj script, from Murrax on Discord.
setopt extended_glob
setopt dot_glob
cdj() {
# Update with your document root folder
if [ -z "$2" ]; then
pushd ~/Documents/JD/*/*/${1}*/
else
pushd ~/Documents/JD/*/*/${1}*/*(#i)($2)**([1])
fi
}
export cdj
I'll quote Murrax for the details:
it lets you go into subfolders too, searching by substring, e.g. cdj 31.14 COMSM0067 puts me in ~/Documents/31 Formal Education/31.14 University of Bristol/+COMSM0067 Advanced Topics in Programming Languages, or if I forget the unit code I can do cdj 31.14 languages
A-maaaa-zing.
100% human. 0% AI. Always.
Footnotes
-
That
cdj()script came from someone else, I didn't write it. If you did, let me know! Authorship is lost to the sands of time. ↩