Quickly go back to a directory instead of typing cd ../../.. (github.com)
Description: Quickly go back to a specific parent directory in bash instead of typing "cd ../../.." redundantly.
How to use:
If you are in this path /home/user/project/src/org/main/site/utils/file/reader/whatever and you want to go to site directory quickly, then just type: 'bd site'
In fact, You can simply type 'bd <starting few letters>' like 'bd s' or 'bd si'
If there are more than one directories with same name up in the hierarchy, bd will take you to the closest. (Not considering the immediate parent.)
Using bd within backticks (`bd <letter(s)>`) prints out the path without changing the current directory.
You can take advantage of that by combining `bd <letter(s)>` with other commands such as ls, ln, echo, zip, tar etc..
Check out the screenshot.
53 comments
[ 3.0 ms ] story [ 101 ms ] threadI made 'bd' out of frustration to use 'cd ../..' all the time from "any" random directory. I can't bookmark all possible places. They are like slightly different tools.
I think it'll be awesome to use both jump and bd in the same system!
Please give 'bd' a try. Once you get used to 'bd', you'll use it frequently without thinking. :)
Anyways z always changes directory. Using bd within backticks will just print the path without changing the directory. We can use that with other commands like ls, zip etc. Example: "ls `bd <starting letters>`" would only print the contents without changing the directory.
In addition to "z foldername" to move around, you can do things like "v vimrc" or "v freetds.conf" to directly edit files, where ever you are.
It's available on homebrew.
In fact, I use history so much, I increased HISTFILESIZE[0] from 1000 commands to 10000.
[0] http://osxdaily.com/2012/04/12/change-length-of-bash-command...
function bd () {
}That way you don't have to execute a separate shell script and source its output. Also note that the "export OLDPWD" wasn't necessary in your script, either. Why pollute the environment of future processes spawned by your shell?
Removed the 'export'. I wrote out of habit. Thanks a lot for pointing that out.
http://www.acm.uiuc.edu/workshops/zsh/cd.html
alias cda='cd ../' alias cdaa='cd ../../' alias cdaaa='cd ../../../'
I guess I was influenced by Lisp at the time, with car, cdr, cdar, cddr, etc ;-)
You saw that naming scheme and thought "wow, that's sensible"?!
"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/"
In fact, I have a lot of .c<dir> aliases that take me directly to various frequented directories.
alias ..1='cd ..'
alias ..2="cd ../.."
alias ..3="cd ../../.."
alias ..4="cd ../../../.."
alias ..5="cd ../../../../.."
`whereis -sq <dirname>`
No extra software necessary.
bind -x '"\C-h":"cd ../;ls"'
(putting it into .bashrc) and then using control-h as a command on the shell to move a directory upwards. very useful for me.
You can use both 'jump' to jump between bookmarked directories and 'bd' to quickly go to a parent directory in the same shell.