Skip to content

Instantly share code, notes, and snippets.

@doughsay
Last active August 29, 2015 14:07
Show Gist options
  • Save doughsay/036960d17e078eaefc88 to your computer and use it in GitHub Desktop.
Save doughsay/036960d17e078eaefc88 to your computer and use it in GitHub Desktop.
Helper functions for coloring and naming iTerm tabs
# Usage:
# Source this script from your Bash start-up script (eg. ~/.bashrc, ~/.bash_profile) (or ~/.zshrc if using zsh, etc.).
#
# Setting titles:
# title something
# title "more than 1 word"
#
# Setting tab colors:
# tab_color 195 89 76
# tab_color 219 154 88
# tab_color 145 185 104
# tab_color 92 155 204
#
# Setting pre-defined tab colors with titles:
# tab_red "Rails Server"
# tab_orange "Rails Console"
# tab_blue "SQL Dev"
# tab_green "Tests"
title_help0()
{
echo "ERROR: No argument provided."
echo "Usage:"
echo " `basename $0` \"title\" to provide a new Terminal title."
}
title_help2()
{
echo "ERROR: Too many arguments provided."
echo "Usage:"
echo " `basename $0` \"title\" to provide a new Terminal title."
}
function set_iterm_title() {
if [ $# -eq 0 ]
then
title_help0;
elif [ $# -eq 1 ]
then
echo -ne "\033]0;$1\007"
elif [ $# -gt 1 ]
then
title_help2;
fi
}
alias title='set_iterm_title'
function titlepwd() {
set_iterm_title `pwd`
}
# Tomorrow Night colors
function tab_red() { title "$1"; tab_color 213 78 83; }
function tab_orange() { title "$1"; tab_color 231 140 69; }
function tab_yellow() { title "$1"; tab_color 231 197 71; }
function tab_green() { title "$1"; tab_color 185 202 74; }
function tab_aqua() { title "$1"; tab_color 112 192 177; }
function tab_blue() { title "$1"; tab_color 122 166 218; }
function tab_purple() { title "$1"; tab_color 195 151 216; }
function tab_color() {
echo -n -e "\033]6;1;bg;red;brightness;$1\a"
echo -n -e "\033]6;1;bg;green;brightness;$2\a"
echo -n -e "\033]6;1;bg;blue;brightness;$3\a"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment