Skip to content

nigelfds/shell-colors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

shell-colors

Tint the iTerm2 window background based on which top-level project folder you're in, so you can tell terminal tabs and windows apart at a glance.

Any directory under ~/projects/<name>/… gets a stable dark background — from a blue / purple / maroon / green family chosen by hashing <name> — with light, faintly-tinted text. Every tab and window inside the same project gets the same color (it's derived from the name, so there's no shared state). Leaving ~/projects resets to your iTerm2 profile default.

The color changes automatically on every cd.

Requirements

  • iTerm2 (uses its proprietary OSC 1337 SetColors escape sequences).
  • zsh.
  • Standard awk and cksum (preinstalled on macOS).

Install

  1. Copy the script to your home directory:

    cp project-colors.zsh ~/.project-colors.zsh
  2. Source it from ~/.zshrc (add near the end):

    # Tint iTerm2 background per top-level ~/projects folder
    [ -f ~/.project-colors.zsh ] && source ~/.project-colors.zsh
  3. Open a new iTerm2 tab (or run source ~/.zshrc).

iTerm2 setting

If the color doesn't change, set Settings → Profiles → Colors → Minimum Contrast to 0 so it doesn't override the foreground color.

Usage

cd ~/projects/drums        # background -> dark blue, light text
cd ~/projects/drums/src    # same color (inherits the top-level name)
cd ~                       # resets to your profile default

Preview all project colors

pc-preview

Prints a swatch for every folder directly under ~/projects, painted in that project's actual background + foreground, followed by the hex values.

Configuration

Set these before the source line in ~/.zshrc:

  • Different projects root:

    PROJECTS_ROOT="$HOME/code"

Tweak the palette by editing __pc_colors in the script:

  • hues=(222 278 348 140) — the four base hues (blue, purple, maroon, green).
  • 0.55 — background saturation.
  • 14 + … % 8 — background lightness range (0.140.21); lower = darker.
  • fg=$(__pc_hsl_to_hex "$hue" 0.20 0.90) — the light text color.

How it works

  • Key = the first folder under ~/projects (${rel%%/*}), so all subfolders inherit the parent's color.
  • Stable color = cksum hash of that name → a family + hue/lightness jitter, so it's identical across every tab, window, and machine.
  • Readable pairing = very dark background (HSL lightness ~0.14–0.21) with a light same-hue foreground (~0.90).
  • Triggers on cd via zsh's chpwd hook; resets to the profile default when you leave ~/projects.

tmux

Escape sequences are wrapped in tmux passthrough when $TMUX is set. You may also need this in ~/.tmux.conf:

set -g allow-passthrough on

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages