Almost every time I open up Terminal, I've wanted three tabs open with three particular directories. That means using Cmd-Tab a lot and tab completion to change the directory. I finally got fed up with that and invented a solution to take care of that automatically.
The first step is creating a "Window group" in the terminal. Go to the menu item "Windows < Save Windows as Group…", make up a name, and make sure "use this group at startup" is checked.
The second step is to edit your ~/.bash_profile and add something like this, where each "if" statement gets a different command. This is adaptable to changing the base directory, sshing, etc.
# change PWD to python by default
function change_default_directory() {
TTYN=$(tty | sed -e 's/.*ttys\([0-9]*\)/\1/')
if [[ $TTYN == 000 ]]; then
cd ~/_code/pytrt/
elif [[ $TTYN == 001 ]]; then
cd ~/_code/_build/pytrt/
elif [[ $TTYN == 002 ]]; then
cd ~/_code/_build/pytrtDEBUG/
elif [[ $TTYN == 003 ]]; then
cd ~/_research/current/
fi
}
if [ -n "$PS1" ]; then
change_default_directory;
fiAdd more elif blocks if you open five windows, take away more if you open fewer. Enjoy!
0 comments:
Post a Comment