Archive for the ‘bash’ Category
Here’s a little snippet that you can stick into your .bashrc file. It creates a hash of the hostname and uses that to color the ps1 variable, so that hosts with similar names look different when you are shelled into them.
function colorps1() { word=`hostname --short` hash=`echo "$word" | md5sum` fullstr="" for l in `echo $word | sed 's/\(...\)/\1\n/g'`; do control="" endcontrol='\[33[00m\]' case "${hash:0:1}" in 0) control='\[33[1;30m\]' ;; 1) control='\[33[0;31m\]' ;; 2) control='\[33[0;32m\]' ;; 3) control='\[33[0;33m\]' ;; 4) control='\[33[0;34m\]' ;; 5) control='\[33[0;35m\]' ;; 6) control='\[33[0;36m\]' ;; 7) control='\[33[0;37m\]' ;; 8) control='\[33[1;30m\]' ;; 9) control='\[33[1;31m\]' ;; a) control='\[33[1;32m\]' ;; b) control='\[33[1;33m\]' ;; c) control='\[33[1;34m\]' ;; d) control='\[33[1;35m\]' ;; e) control='\[33[1;36m\]' ;; f) control='\[33[1;37m\]' ;; esac hash=${hash:1} fullstr="$fullstr$control$l" done fullstr="\[33[1;31m\]\\u@$fullstr$endcontrol \[33[1;34m\]\W \$ \[33[00m\]" export PS1=$fullstr } colorps1