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.
![git zsh rd function shell output](https://sfo2.digitaloceanspaces.com/revsys-com-prod-media/images/git-bash-rd.width-800.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=X4TI6FSBIKO5PE7QO3JH%2F20240727%2Fsfo2%2Fs3%2Faws4_request&X-Amz-Date=20240727T094048Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=725a326090ee1ab318259256df4a722d89900d6438780e20bbb444303742af35)
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