Created
June 30, 2011 18:50
-
-
Save jlong/1056902 to your computer and use it in GitHub Desktop.
Drop in .bash_profile to always remember the working directory between sessions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Remember the current directory | |
if [ `type -t cd` == builtin ]; then | |
cd () | |
{ | |
builtin cd "$@" | |
pwd > ~/.working-directory | |
} | |
else | |
# Alias the cd function (needed if you run RVM) | |
eval "$(echo "__cd_without_cwd()"; declare -f cd | tail -n +2)" | |
cd () | |
{ | |
__cd_without_cwd "$@" | |
pwd > ~/.working-directory | |
} | |
fi | |
if [[ -e ~/.working-directory ]]; then cd $(cat ~/.working-directory); fi |
That doesn't work between sessions. What this lets me do is cd
into a project directory and open a couple of tabs in the same directory. It also remembers where I was when I open Terminal the next time.
What I realized was that the default behavior of always starting in the home directory when I create a new session is rarely what I want. A large percentage of the time I want to go back to whatever I was working on before. And cd ~
is easy enough to type if I need to actually be in my home directory.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you know about
cd -
right?