Skip to content

Instantly share code, notes, and snippets.

@Martin91
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save Martin91/d718115916d6ed1ef0a7 to your computer and use it in GitHub Desktop.

Select an option

Save Martin91/d718115916d6ed1ef0a7 to your computer and use it in GitHub Desktop.
set iTerm2 tab chrome background color according to the current working directory
function auto_set_tab_chrome_background_color {
# Red component value is calculated from the full path of current directory
RR=`pwd | wc -m`
let RR=(RR%25)*10
# Green component value is calculated from the basename of current directory
GG=`basename \`pwd\` | wc -m`
let GG=(GG%25)*10*2
# Blue component value is calculated from the full total files and directories count under this directory
BB=`ls | wc -l`
let BB=(BB%25)*10
# start to set background color of tab chrome
# Documents: http://iterm2.com/documentation-escape-codes.html
echo -en "\033]6;1;bg;red;brightness;${RR}\a" # -n: ignore newline
echo -en "\033]6;1;bg;green;brightness;${GG}\a"
echo -en "\033]6;1;bg;blue;brightness;${BB}\a"
}
function cd {
# actually change the directory with all args passed to the function
builtin cd "$@"
auto_set_tab_chrome_background_color;
}
# should append this line to ~/.bashrc or ~/.bash_profile so that the function will get running
# when each time you open a new shell window
auto_set_tab_chrome_background_color;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment