* Add different colors for remote hosts
authorDon Armstrong <don@donarmstrong.com>
Mon, 22 Oct 2007 23:22:45 +0000 (23:22 +0000)
committerDon Armstrong <don@donarmstrong.com>
Mon, 22 Oct 2007 23:22:45 +0000 (23:22 +0000)
.bashrc

diff --git a/.bashrc b/.bashrc
index 189377b..56950bf 100644 (file)
--- a/.bashrc
+++ b/.bashrc
@@ -32,7 +32,24 @@ if [ "$PS1" ]; then
 
     # set a fancy prompt
     #printf '\33]2;%s\007'
-    PS1="\[\033[0;36m\]\h \t \w$\[\033[0m\] "
+    # we want to set the color based on what machine we're on
+    # if it's a remote, SSH_CONNECTION will be set
+    if [ -n "$SSH_CONNECTION" ]; then
+       # figure out what color to use
+       COLOR=$(hostname|md5sum|perl -ne 'if (/^([a-f\d]{8})/) {
+              my $num = unpack(q(L),pack(q(h*),$1));
+              my @col = map {(qq(0;${_}m),qq(1;${_}m))} 31..37;
+              my $col = $col[$num%$#col];
+              if ($col eq q(0;36m)) {
+                 $col = q(1;30m);
+              }
+              print $col;
+              }')
+       PS1="\[\033[$COLOR\]\h \[\033[0;36m\]\t \w$\[\033[0m\] "
+       unset COLOR
+    else
+       PS1="\[\033[0;36m\]\h \t \w$\[\033[0m\] "
+    fi;
     # \[\033[1;36m\][\w]\n\[\033[0;36m\][\h|\t]$ \[\033[0m\]
 
     # make sure the term we're using exists in the termcap