Hacker News new | past | comments | ask | show | jobs | submit login

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/"




Similarly, 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.


Note 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.


Yup. Perhaps `git rev-parse --show-toplevel` is better for this alias.


I 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.


zshell automatically links `cd` to `pushd`, which means you can go back with `popd`.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: