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

Re: Shell prompts (was Re: floppy permissions)



On Wed, Apr 18, 2001 at 12:48:55AM -0700, Karsten M. Self wrote:
> Not half bad.  My own approach is slightly more subtle, but reasonably
> effective:
> 
>     function proml
>     {
>     case $TERM in
> 	xterm*|rxvt|eterm|wterm)
> 	    local TITLEBAR='\[\033]0;\u@\h:\w\007\]'
> 	    ;;
> 	*)
> 	    local TITLEBAR=''
> 	    ;;
>     esac
> 
>     PS1="${TITLEBAR}\
>     [\[\033[7m\]\u\[\033[0m\]@\h:\W]\
>     \$ "
>     PS2='> '
>     PS4='+ '
>     }
> 
>     proml
>     unset proml
>     export PS1
> 
> This results in a highlighted prompt for root (the escape sequences),
> while my standard prompt is just plaintext.

<confrontation mode=head-butt>oh yeah? looks to me like this only checks
whether you're running under an X-window *term versus the console, not whether
you're logged in as root. aha! gotcha!</confrontation>

here's my iteration on top of your stuff, and <flameproof suit at hand> please
feel free to gimme pointers on how to make this (particularly colors) more
modular...

function munge_ps1
{
	local TITLEBAR=''
	local PROMPT='$'

	if [ "$BASH" ]; then
		local COLOR='43;34;3'
		if [ $EUID = '0' ] ; then
			COLOR='41;33;1'
			PROMPT='#'
		fi
		PROMPT="\e[${COLOR}m\u@\h\e[37;40;1m: \w \e[0m\n${PROMPT}"
	else
		if [ "`id -u`" -eq 0 ]; then
			PROMPT='#'
		fi
	fi

	case $TERM in
		xterm*|rxvt|eterm|wterm)
			TITLEBAR='\[\e]0;\u@\h:\w\007\]'
			;;
		*)
			TITLEBAR=''       
			;;  
	esac

	PS1="${TITLEBAR}${PROMPT} "
}

-- 
don't visit this page. it's bad for you. take my expert word for it.
http://www.salon.com/people/col/pagl/2001/03/21/spring/index1.html

will@serensoft.com
http://sourceforge.net/projects/newbiedoc -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!



Reply to: