Skip to content

Instantly share code, notes, and snippets.

@pudquick
Created March 28, 2023 19:57
Show Gist options
  • Save pudquick/0ec1b734aaa33fe8bf055003954980e2 to your computer and use it in GitHub Desktop.
Save pudquick/0ec1b734aaa33fe8bf055003954980e2 to your computer and use it in GitHub Desktop.
Change color in Terminal tab depending on current working directory in zsh
# put this in your .zshrc
function background_danger_color_change() {
case $PWD/ in
/Users/frogor/dangerous/*)
# uh oh, be careful in here
osascript<<END
tell application "Terminal"
get the background color of the selected tab of the front window
if the result is not equal to {65535, 0, 0} then
set the background color of the selected tab of the front window to {65535, 0, 0}
end if
end tell
END
;;
*)
# reset it back, if we're not in dangerous land
osascript<<END
tell application "Terminal"
get the background color of the selected tab of the front window
if the result is equal to {65535, 0, 0} then
set the background color of the selected tab of the front window to {5866, 5866, 5866}
end if
end tell
END
;;
esac
}
chpwd_functions=(${chpwd_functions[@]} "background_danger_color_change")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment