I've always liked the idea of having a different background color for terminals where I'm logged in as root. I've always used serveral terminals for this, but it gets quite tiresome to open up a new .term-file or similar, just to get another background color, so I came up with this solution:
- Use AppleScript to tell the current terminal to change background color
- Use an alias/function in bash to invoke the AppleScript each time su is run
setBackground() {
osascript -e "tell application \"iTerm\"
set current_terminal to (current terminal)
tell current_terminal
set current_session to (current session)
tell current_session
set background color to $1
end tell
end tell
end tell"
}
su() {
( setBackground "{15000,0,0}" & )
( exec su $* )
( setBackground "{0,0,0}" & )
}
The first function tells iTerm to change colors, and the second "replaces" su, so that this function is executed whener I type su at the prompt. Unfortunately, there are some unwanted behaviours with this, such as if you try to run su from Terminal with the script above, it will change the color of an iTerm. I'm sure there are other bugs as well, but I haven't noticed any yet.
•
[12,582 views]

