Production is Red, Development is Blue
jeffmiller.github.com
jeffmiller.github.com
PS1='\[\e[1;31m\][\u@\h \W]\$\[\e[0m\] '
We use this in our production environments and the red prompt, though not as jarring as a red background, is still scary enough to serve its purpose.
One upside in setting this up on the server, as opposed to local like the OP, is that all connections in will get the red prompt.
txtblk='\e[0;30m' # Black - Regular
txtred='\e[0;31m' # Red
txtgrn='\e[0;32m' # Green
txtylw='\e[0;33m' # Yellow
txtblu='\e[0;34m' # Blue
txtpur='\e[0;35m' # Purple
txtcyn='\e[0;36m' # Cyan
txtwht='\e[0;37m' # White
bldblk='\e[1;30m' # Black - Bold
bldred='\e[1;31m' # Red
bldgrn='\e[1;32m' # Green
bldylw='\e[1;33m' # Yellow
bldblu='\e[1;34m' # Blue
bldpur='\e[1;35m' # Purple
bldcyn='\e[1;36m' # Cyan
bldwht='\e[1;37m' # White
unkblk='\e[4;30m' # Black - Underline
undred='\e[4;31m' # Red
undgrn='\e[4;32m' # Green
undylw='\e[4;33m' # Yellow
undblu='\e[4;34m' # Blue
undpur='\e[4;35m' # Purple
undcyn='\e[4;36m' # Cyan
undwht='\e[4;37m' # White
bakblk='\e[40m' # Black - Background
bakred='\e[41m' # Red
badgrn='\e[42m' # Green
bakylw='\e[43m' # Yellow
bakblu='\e[44m' # Blue
bakpur='\e[45m' # Purple
bakcyn='\e[46m' # Cyan
bakwht='\e[47m' # White
txtrst='\e[0m' # Text Reset
[1] https://wiki.archlinux.org/index.php/Color_Bash_Prompt ESC=$'\x1b'
# Terminal color escapes
colornames=(BLACK RED GREEN YELLOW BLUE MAGENTA CYAN)
for i in ${!colornames[@]}; do
eval "${colornames[$i]}=\"${ESC}[3${i}m\""
eval "BG${colornames[$i]}=\"${ESC}[4${i}m\""
done
# There are holes in this sequence, so it doesn't loop nicely
BOLD="${ESC}[1m"
DARK="${ESC}[2m"
UNDERLINE="${ESC}[4m"
BLINK="${ESC}[5m"
INVERSE="${ESC}[7m"
RST="${ESC}[m"
styles=(BOLD DARK UNDERLINE BLINK INVERSE RST)
# and the PS1-safe versions of the above
for i in ${colornames[@]} ${colornames[@]/#/BG} ${styles[@]}; do
eval "PS$i=\"\\[\$$i\\]\""
done
Having color escapes in shell variables comes in handy from time to time (like faking 'colordiff' with sed). if [[ ${EUID} == 0 ]] ; then
PS1='\[\033[01m\][ \[\033[01;31m\]\u@\h \[\033[00m\]\[\033[01m\]] \[\033[01;32m\]\w\[\033[00m\]\n\[\033[01;31m\]\$\[\033[00m\]> '
else
PS1='\[\033[01m\][ \[\033[01;34m\]\u@\h \[\033[00m\]\[\033[01m\]] \[\033[01;32m\]\w\[\033[00m\]\n\[\033[01;34m\]\$\[\033[00m\]> '
fi
Interesting to think about using it across servers, though.A little clunky, I'll admit. I'd like to hear any more graceful solutions.
If set, the value is executed as a command prior to issuing each primary prompt.
e.g.: PROMPT_COMMAND='[[ "$PWD" =~ ^/sensitive/area ]] && PS1="be careful: " || PS1="normalprompt: "'PS1="\[\e[1;31m\]$PS1\[\e[0m\]"
better to print too long a url for some than too short for things like example.github.com, code.google.com, etc.
$ fab deploy
... oups errors on the website even if tested on stagging ...
$ fab getdebuglog
$ fab rollback
... fix test ...
$ fab deploy
fab is fabric, a very very nice deployment tool in Python: http://www.fabfile.orgBut I agree with the sentiment - think very hard before doing this, and don't make it a habit.
http://en.wikipedia.org/wiki/Expect
Slightly weird syntax, but learnable in a few hours. You are likely to already have it on your machines.
Having the ability to immediately stage an environment to reproduce an error without configuration issues would really take a lot of treachery out of trying to evolve larger systems.
In fact, an expect script [can be] nicely self-documenting, because somebody can look at it and see "oh these are the steps to deploy X" because the scripts basically read as "at the foo prompt, enter bar" over and over again, with some branching to handle varying responses (missing prereq, error messages).
The "ultimate" in building environments would probably have to be something more comprehensive and declarative like bcfg (http://trac.mcs.anl.gov/projects/bcfg2) which I have seen in action and it works but is very XML-heavy.
I've been burned too many times when jumping back and forth between production and dev browser tabs. This simple hack saves me time, and possibly some headaches.
Also, you can use different colors for different QA boxes--"I need blue qa deployed" or "That fix is in black qa".
(Yes, this was an enterprise environment, why do you ask?)
Production is red for me too. Like this: http://img.ly/images/663862/full
However... the color coding can be a bit misleading sometimes, particularly if you are chaining SSH sessions and the colors are being set on terminal launch (not on shell login). I was using PuTTY config settings for color on my company-mandated Windows machine and soon found the limitations of this when I logged in to machine A (green), then from there to machine B (red). The terminal was still green and some time later I trusted the color and ran a (destructive) command in the wrong shell. This reinforced to me that while useful, color is no substitute for thinking before typing, and double checking everything before performing destructive operations :-)
However, I like the idea in general, just not the implementation. It would be nice if modern terminal emulators (hello iTerm!) could adopt new escape sequences to do things like set a background color on the tab (like ZOC and some others support by client-side configuration).
There is still lots of room for innovation in the terminal, it's a bit sad to see progress at such a glacial pace. I'd actually pay for a terminal emulator that's fast (first priority) and then also makes my life easier with innovative features like the above.
For some reason all innovation in the terminal space seems to have died when dialup BBS went out of fashion 10 years ago. Most terminal emulators have even moved backwards and don't support ZModem anymore, which could be very useful to provide adhoc drag'n'drop uploads instead of the scp/rsync limbo that is so common nowadays.
Host someproductionbox
LocalCommand xtermcontrol --bg=red
Host sometestbox
LocalCommand xtermcontrol --bg=blueThere's no way to change profile from the command line using gnome-terminal, unfortunately, but there is "roxterm" which is very similar in functionality and lets you do the following to change the color scheme of the current terminal window:
dbus-send --session /net/sf/roxterm/Options net.sf.roxterm.Options.SetColourScheme string:$ROXTERM_ID "string:NAME_OF_COLOR_SCHEME"Uncomment 'force_color_prompt=yes' Edit the line following if color_prompt is yes. By default it's green (1;32m). Red is 0;31m.
Make sure to make a copy of the .bashrc file before starting.
function settitle {
echo -en "\e]0; $* \a"
}
function ssh {
settitle ssh $*
echo /usr/bin/ssh $*
/usr/bin/ssh $*
}
function sftp {
settitle sftp $*
echo /usr/bin/ssh $*
/usr/bin/sftp $*
}
No, it's not bright and colorful, but it does a good job of telling me where the gnome-terminal I'm using is connected to.And so are you.