Using Shell Functions to Jump Into Terminal Projects
If you are like me, you often have number of terminal windows open and logged into another machine. When that machine reboots, you need to log in again and pick up where you left off.
This post covers putting a shell function in .profile to easily jump between projects. A function for setting the terminal title is also provided. This post is written for sh. If you are using another shell, the same principles apply, but the details may be a little different.
Software Versions
Instructions
First, create a few test directories.
Next, add the following to $HOME/.profile
.profile
The above function can be used to set the terminal title. Reload the profile your open terminal and open a couple more terminals.
You now have three named terminals working on three different projects. The above works, but we can do better. Add the following to $HOME/.profile
.profile
Close all but one terminal and reload $HOME/.profile
Switch between projects with the following commands. Notice that the terminal title changes when switching from project to project.
The terminal title can also be specified with the project. Open another terminal and enter the following commands. This simulates a pair of terminals- one for development and one for preview.
In the examples in this post, the case statements just cd into the project directory, but other commands can be added on a project by project basis. The admin case is an example of this.
Replace the test project cases in this post with your real projects. Remove the test directories when you no longer need them.
If you work with ssh key based git, consider installing keychain and adding the following line to your profile.