Created
November 29, 2015 00:59
-
-
Save dustractor/f2f6b149d8d4d78e5b82 to your computer and use it in GitHub Desktop.
Python script to change iTerm2 titlebar color. Supply three or six digit hex color string on the command line and it will convert to iTerm2 escape codes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
# usage: tabcolor '#FF00FF' | |
import sys | |
if len(sys.argv) > 1: | |
color = sys.argv[-1] | |
if color[0] == "#" and len(color) in {7,4}: | |
rgb = color[1:] | |
rc,gc,bc = {3:(rgb[0]*2,rgb[1]*2,rgb[2]*2,),6:(rgb[0:2],rgb[2:4],rgb[4:6])}[len(rgb)] | |
r,g,b = (int(n,base=16) for n in (rc,gc,bc)) | |
sys.stdout.write("\033]6;1;bg;red;brightness;%d\a" % int(r)) | |
sys.stdout.write("\033]6;1;bg;green;brightness;%d\a" % int(g)) | |
sys.stdout.write("\033]6;1;bg;blue;brightness;%d\a" % int(b)) | |
elif color.count("."): | |
r,g,b = map(float,sys.argv[-1].split(",")) | |
sys.stdout.write("\033]6;1;bg;red;brightness;%d\a" % int(r * 255)) | |
sys.stdout.write("\033]6;1;bg;green;brightness;%d\a" % int(g * 255)) | |
sys.stdout.write("\033]6;1;bg;blue;brightness;%d\a" % int(b * 255)) | |
else: | |
r,g,b = (0,0.147,0.159) | |
sys.stdout.write("\033]6;1;bg;red;brightness;%d\a" % int(r * 255)) | |
sys.stdout.write("\033]6;1;bg;green;brightness;%d\a" % int(g * 255)) | |
sys.stdout.write("\033]6;1;bg;blue;brightness;%d\a" % int(b * 255)) | |
sys.stdout.flush() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment