3 ms·
Two other simple tips without requiring a script: "cd -" will jump back to the last directory you were at, regardless of where it is. Add this to your .bashrc
by philfreo 13y ago
Two other simple tips without requiring a script:
"cd -" will jump back to the last directory you were at, regardless of where it is.
Add this to your .bashrc / .zshrc / whatever:
alias cdg='cd $(git rev-parse --show-cdup)'
And then type "cdg" to keep going up directories until you reach whichever folder contains your git repo. Useful when going from "/Users/philfreo/Projects/myproject/myproject/src/assets/js/views/" back up to "/Users/philfreo/Projects/myproject/"
- tytso 13y agoNote that "git rev-parse --show-cdup" return the empty string if you are at the top of the git repo. So "cdg" as defined above will drop you in the hope directory if you are already at the top of your git tree.
- davvid 13y agoYup. Perhaps `git rev-parse --show-toplevel` is better for this alias.
- wging 13y agoSimilarly, in zsh cd -n will take you to the nth-most-recent directory. 'dirs -v' will show the current state of the directory stack... you can do things like "dirs -v" + "cd -6" to figure out the number to use, then go to that directory.
- dhimes 13y agoI just have an alias .cgit='cd /home/<user>/<...>/<repodir>' In fact, I have a lot of .c<dir> aliases that take me directly to various frequented directories.
- tghw 13y agozshell automatically links `cd` to `pushd`, which means you can go back with `popd`.