Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
macOS Terminal bash_profile script to color windows by directory
set_terminal_color() {
osascript -e "tell application \"Terminal\"
set current settings of window 1 to settings set \"$window_color\"
end tell"
}
colorize_terminal() {
update_terminal_cwd
if [ "$PWD" != "$MYOLDPWD" ]; then
MYOLDPWD="$PWD";
x="$PWD"
while [ "$x" != "/" ] ; do
if [[ `find "$x" -maxdepth 1 -name .window_color` ]]; then
window_color=`cat $x/.window_color`
set_terminal_color
break
fi
x=`dirname "$x"`
done
if [ "$x" == "/" ] ; then
window_color=`defaults read com.apple.Terminal "Default Window Settings"`
set_terminal_color
fi
fi
}
#
export PROMPT_COMMAND=colorize_terminal
# A convenience command to set the color for the current directory
dircolor() {
window_color=`sed -e 's/^"//' -e 's/"$//' <<<"$1"`
set_terminal_color
echo "$window_color" > .window_color
MYOLDPWD="$PWD";
}
@kelnishi

This comment has been minimized.

Copy link
Owner Author

commented Jul 22, 2019

Just stick it in your .bash_profile and use dircolor something to set the window color for the directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.