Per-directory terminal colors in fish shell

My terminal background color changes based on the current directory. It's a small touch that makes it easy to tell which project I'm in at a glance, which is especially useful when juggling AI agents.

It works via a custom fish function called _color_for_dir, which:

1. Hashes the current $PWD

2. Maps the hash to a hue (0-359)

3. Converts it to a dark RGB color

4. Sends an OSC 11 escape sequence to change the terminal background

It's deterministic, so each directory always gets the same color. The function is triggered on startup and on every cd via a --on-variable PWD event listener.

It also skips VS Code's integrated terminal because I generally know what projects I have open

Full code:

Click to expand

function _claude_color_for_dir

Skip in VS Code's integrated terminal

if test "$TERM_PROGRAM" = vscode return end

end

添加评论
点赞收藏
点踩分享查看原文
评论
?
参与讨论