From 99b914fe2b1ef8c4d063b636cd46cc3ffdfd6c3f Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Fri, 5 Dec 2008 13:18:51 +0000 Subject: [PATCH] Different prompt colours according to the number of supported colours. No longer allow user override of prompt colours. git-svn-id: https://svn.cambridge.iain.cx/profile/trunk@163 6be0d1a5-5cfe-0310-89b6-964be062b18b --- .profile.d/ps1.bashrc | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/.profile.d/ps1.bashrc b/.profile.d/ps1.bashrc index 29fa704..5f023f8 100644 --- a/.profile.d/ps1.bashrc +++ b/.profile.d/ps1.bashrc @@ -10,18 +10,29 @@ # bash complaining about not knowing them when you su to another user, # retaining PS1 but not the function definitions. # -# Override the PROMPT_OK_COLOUR and PROMPT_FAILED_COLOUR environment variables -# to set different colours. -# # To use, add a call to __ps1 in your .bash_profile file. # -export PROMPT_OK_COLOUR=${PROMPT_OK_COLOUR:-32} -export PROMPT_FAILED_COLOUR=${PROMPT_FAILED_COLOUR:-31} +case $(tput colors) in + 256) + export PROMPT_OK_COLOUR="1;38;5;34" + export PROMPT_FAILED_COLOUR="1;38;5;160" + ;; + + 88) + export PROMPT_OK_COLOUR="1;38;5;24" + export PROMPT_FAILED_COLOUR="1;38;5;48" + ;; + + *) + export PROMPT_OK_COLOUR="1;32" + export PROMPT_FAILED_COLOUR="1;31" + ;; +esac function __ps1() { - export PS1='\u@\[\033[1;$(__ps1_col $?)m\]\h\[\033[0m\]$(__ps1_ret $?):\w\$ ' - export PS1='\u@\[\033[1;$(__ps1_col $? 2>/dev/null)m\]\h\[\033[0m\]$(__ps1_ret $? 2>/dev/null):\w\$ ' + export PS1='\u@\[\033[$(__ps1_col $?)m\]\h\[\033[0m\]$(__ps1_ret $?):\w\$ ' + export PS1='\u@\[\033[$(__ps1_col $? 2>/dev/null)m\]\h\[\033[0m\]$(__ps1_ret $? 2>/dev/null):\w\$ ' return 0 } -- 2.7.4