[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Colorized Prompts Problem - Thanks for the Deconstruction



On Fri, May 15, 2015 at 09:49:12PM -0500, David Wright wrote:
> Quoting Thomas H. George (lists@tomgeorge.info):
> > > 
> > Your explanation is very helpful, converts the jumble I copied from a
> > website into a logical sequence of instructions. I really appreciate
> > being able to understand the meaning of the prompt.
> 
> This conversation made me revisit my own prompt which I have now
> modified. I thought I'd share it with you in case any part of it
> should be helpful.
> 
> LOCAL_COLOR is set in a host-specific file that also sets things like
> different colours for midnight commander (mc) so I know which host I'm on.
> 
> PROMPT_COMMAND adds a space after the return code and then removes
> itself if it would print zero. It also sets the title-bar in an xterm,
> again so I know where I am. (I have a couple of dozen xterms, some
> ssh'd to other hosts.) Putting the tty number in the title bar makes
> it easier to kill an xterm should it freeze.
> 
> PS1 makes any non-zero return code stand out; then the local colour
> takes over the rest of the prompt. Note that the "0;" is required in
> LOCAL_COLOR to cancel the earlier "1;" that highlights the return code.
> Breaking the PS1 line into 3 parts avoids another level of quoting.
> 
> 
> LOCAL_COLOR='\e[0;34m' # blue (this is in ~/.bash-<hostname>)
> 
> export PROMPT_COMMAND='MYPROMPT="$? " && [ "$MYPROMPT" = "0 " ] && MYPROMPT=""'
> case $TERM in
>     xterm*)
> 	export PROMPT_COMMAND+=" || echo -ne '\e]0;${HOSTNAME^^}          $(tty)          ${HOSTNAME^^}\a'"
> 	;;
> esac
> 
> export PS1='\[\e[1;33;41m\]$MYPROMPT\['
> export PS1+="$LOCAL_COLOR"
> export PS1+='\]\H!\u \t \w \$ \[\e[m\]'
> unset LOCAL_COLOR


Is all that in one file? Is it sourced via .bashrc?



-- 
"If you're not careful, the newspapers will have you hating the people
who are being oppressed, and loving the people who are doing the 
oppressing." --- Malcolm X


Reply to: