[TAG] 2-cent Tips: Same prompt different term
Benjamin A. Okopnik
ben at linuxgazette.net
Thu Oct 26 01:04:18 MSD 2006
On Wed, Oct 25, 2006 at 02:18:37PM -0400, Andrew Elian wrote:
> Hello.
>
> Here's a quick tidbit to help the PS1 variable do the right thing
> depending on the terminal - X or otherwise. I've added these lines to
> my .bash_profile and found them useful:
>
> case $TERM in
>
> xterm)
> export TERM=xterm-color
> export PROMPT_COMMAND='echo -ne "\033]0;${USER}:${PWD/#$HOME/~}\007"'
> export PS1="$ "
> ;;
>
> rxvt|Eterm)
> export PROMPT_COMMAND='echo -ne "\033]0;${USER}:${PWD/#$HOME/~}\007"'
> export PS1="$ "
> ;;
>
> linux)
> export PS1="\[\033[0;32m\]\u \[\033[1;32m\]\W]\[\033[0;32m\] "
> ;;
> esac
Nice! That should come in useful for anyone using different types.
Fortunately, they all use the same 'xterm*' entries in the .Xresources
file, so other bits of behavior, etc. don't need to be adapted.
Somewhat in the same vein, I like to distinguish between consoles 1-3 by
setting different colors (I also use red, but it's reserved for root
logins). From my ~/.bash_profile:
```
TTY=`tty`
[ ${TTY:5:3} == "tty" ] && { # If not a console, bail!
color=(x blue green magenta) # tty's start at 1, arrays at 0...
setterm -foreground ${color[${TTY#*y}]} -store
}
'''
* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET *
More information about the TAG
mailing list