Short story: I wanted to distinguish my terminal windows between local sessions, ssh sessions and vagrant sessions.
SSH_THEME="SSH" VAGRANT_THEME="Vagrant" set_th () { osascript -e "tell app \"Terminal\" to set current settings of first window to settings set \"$1\"" } set_id () { osascript -e "tell app \"Terminal\" to set current settings of first window to $1 $2 $3 $4" #$@ does not work! } get_id () { cur_id=$(osascript -e "tell app \"Terminal\" to get current settings of first window") } ssh(){ #!/bin/sh get_id set_th $SSH_THEME /usr/bin/ssh "$@" set_id $cur_id } vagrant(){ #!/bin/sh if [ $1 = "ssh" ]; then get_id set_th $VAGRANT_THEME /opt/vagrant/bin/vagrant "$@" set_id $cur_id else /opt/vagrant/bin/vagrant "$@" fi }
The code creates a temporary variable of the current theme before switching. So, when ending the session, the original theme changes back instead of a fixed one.
Putting the above code in your .bash_profile
: gives the following nice behavior:
Color coding your sessions is a great way to visualize things and make sure you do not take any unwanted action by mistake 🙂
Of course, the code can be used to wrap any application. For instance, one could use it to make the interactive interpreter of Python/Sage or terminal sessions using torsocks
appear in different colors or even fonts.