I've recently been on a mission to take my own advice and spend a little bit of time each week optimizing my personal coding setup. Recently I constantly need to got to the root of the current git repository I'm in.
It doesn't sound like a big deal, does it?
It isn't that big of a deal. However, it's keeping me from dozens to hundreds of `cd ../../..` type keystrokes every day! This won't single-handedly keep RSI away, but every little bit helps.
So what did I set up? I set up two zsh aliases.
- `r` which will immediately cd me to the root of the current git repository I'm in
- `rd` which will run the fd command from the perspective of the root of the git repo
I'm on OSX, so the only new dependency was I needed to install `git-extras` with `brew install git-extras`. git-extras is useful all on it's own, but I haven't used that many of its features yet. My muscle memory for such things takes awhile to set in as I'm sure it does for you.
I added the following to the end of my `~/.zshrc`:
# Git customization alias r='cd $(git root)' function rd() { fd "$1" $(git root) }
Now, if I type `r` I'm immediately taken to the git root. And if I run `rd settings` from a couple of directories deep in a code base I get.
I hope you'll join me in taking a little time to improve our workflows for better developer experience (DX) and a slightly easier day!
Fish Shell Version
Daniel worked up the fish shell version for us all
# ~/fish-configs/functions/r.fish function r cd (git root) end function rd -a pattern fd "$pattern" (git root) end