Created
August 16, 2025 18:50
-
-
Save jimbocoder/be1d7e5252335503a3500862360a7b8f to your computer and use it in GitHub Desktop.
colorful iterm2 tabs based on $PWD
This file contains hidden or 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
# Disclaimer: yes, this is kind of silly and the implementation is definitely | |
# not optimal. | |
# Problem: | |
# Lately I do a lot of work in the terminal across a lot of | |
# directories that have similar names, and similar contents. Configuring the | |
# terminal window title, or tab title, with things like the current directory, | |
# or current foreground process, doesn't really help me keep track of what's | |
# where. All the tabs look the same, and even a quick `ls` usually just yields | |
# very similar contents. I find myself doing `pwd` often just to get | |
# re-oriented. | |
# | |
# Solution: | |
# Use the current directory to give each tab a random color. Use the directory | |
# as the seed to the RNG, so any tab in that directory always gets the same color. | |
# Use medium-saturation colors to avoid being super ugly. | |
# | |
autoload -U add-zsh-hook | |
change_tab_color_using_cwd() { | |
tabcolor=$(python -c ''' | |
import colorsys; | |
import os; | |
import random; | |
random.seed(os.getcwd()); | |
hue = random.random(); | |
rgb = colorsys.hsv_to_rgb(hue, .5, 1.0); | |
hex = "".join([hex(int(_*255))[2:] for _ in rgb]); | |
print(hex); | |
''') | |
it2setcolor tab $tabcolor | |
} | |
add-zsh-hook chpwd change_tab_color_using_cwd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment