Created
July 22, 2019 20:37
-
-
Save kelnishi/c522a97b43ea42bc50b07b25bf824a0d to your computer and use it in GitHub Desktop.
macOS Terminal bash_profile script to color windows by directory
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
| 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"; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just stick it in your .bash_profile and use dircolor something to set the window color for the directory.