Home | Photos | Family | Linux | Motorcycling | Work
NOTE: There are 9 links related to this category.

Neat-o prompts...

Being an old BBS guy, I love any text display that makes liberal use of ANSI color. :) Your system-wide prompt (in RedHat, Mandrake, and others I'm sure) can be changed in /etc/bashrc (assuming you use bash). To make our lives easier, add this stuff first at the top of your bashrc file:

# Define colors for pretty prompts....

GRAY="\[\033[1;30m\]"
LIGHT_GRAY="\[\033[0;37m\]"
BLUE="\[\033[0;34m\]"
LIGHT_BLUE="\[\033[1;34m\]"
CYAN="\[\033[0;36m\]"
LIGHT_CYAN="\[\033[1;36m\]"
GREEN="\[\033[0;32m\]"
LIGHT_GREEN="\[\033[1;32m\]"
RED="\[\033[0;31m\]"
LIGHT_RED="\[\033[1;31m\]"
PURPLE="\[\033[0;35m\]"
LIGHT_PURPLE="\[\033[1;35m\]"
BROWN="\[\033[0;33m\]"
YELLOW="\[\033[1;33m\]"

So, with that out of the way, here are the custom prompts I use for my Linux systems.
Here's the one I use for my "User" machines:

PS1="$BLUE=$LIGHT_BLUE=$CYAN[$LIGHT_CYAN\d at \@$CYAN] [
$LIGHT_CYAN\j jobs$CYAN]$LIGHT_BLUE=$BLUE=\n$BLUE=$LIGHT_BLUE=$CYAN[
$LIGHT_CYAN\u@\h$CYAN] $BROWN[$YELLOW\w$BROWN]
$LIGHT_RED\\$ $LIGHT_GRAY"
Which looks like this:

On my Server machines I use something a little simpler. You'll notice that this looks a little different. I did this one when I prefered to do things the hard way, so the actual ANSI codes are embeded in there, instead of using the variables like above.

PS1="\[\033[1;34m\][\[\033[1;36m\]\d \t\[\033[1;34m\]]
 \[\033[1;34m\][\[\033[1;36m\]\u@\h\[\033[1;34m\]]
 \[\033[1;34m\][\[\033[1;36m\]\w\[\033[1;34m\]]\\$ \[\033[1;36m\] "
Which looks like this:

On my firewalls, I make the use red instead of blue to differentiate the different machines.

To put it in context, here is my bashrc file:

# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# Define colors for pretty prompts....

GRAY="\[\033[1;30m\]"
LIGHT_GRAY="\[\033[0;37m\]"
BLUE="\[\033[0;34m\]"
LIGHT_BLUE="\[\033[1;34m\]"
CYAN="\[\033[0;36m\]"
LIGHT_CYAN="\[\033[1;36m\]"
GREEN="\[\033[0;32m\]"
LIGHT_GREEN="\[\033[1;32m\]"
RED="\[\033[0;31m\]"
LIGHT_RED="\[\033[1;31m\]"
PURPLE="\[\033[0;35m\]"
LIGHT_PURPLE="\[\033[1;35m\]"
BROWN="\[\033[0;33m\]"
YELLOW="\[\033[1;33m\]"

# by default, we want this to get set.
# Even for non-interactive, non-login shells.
if [ `id -gn` = `id -un` -a `id -u` -gt 99 ]; then
        umask 002
else
        umask 022
fi

# are we an interactive shell?
if [ "$PS1" ]; then
    if [ -x /usr/bin/tput ]; then
      if [ "x`tput kbs`" != "x" ]; then # We can't do this with "dumb" terminal
        stty erase `tput kbs`
      elif [ -x /usr/bin/wc ]; then
        if [ "`tput kbs|wc -c `" -gt 0 ]; then # We can't do this with "dumb" terminal
          stty erase `tput kbs`
        fi
      fi
    fi
    case $TERM in
        xterm*)
                if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
                        PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
                else
                PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
                fi
            ;;
        *)
                [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
            ;;
    esac
    [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="$BLUE=$LIGHT_BLUE=$CYAN
[$LIGHT_CYAN\d at \@$CYAN] [$LIGHT_CYAN\j jobs$CYAN]
$LIGHT_BLUE=$BLUE=\n$BLUE=$LIGHT_BLUE=$CYAN[$LIGHT_CYAN\u@\h$CYAN] $BROWN
[$YELLOW\w$BROWN]$LIGHT_RED\\$ $LIGHT_GRAY"

    if [ "x$SHLVL" != "x1" ]; then # We're not a login shell
        for i in /etc/profile.d/*.sh; do
            if [ -x $i ]; then
                . $i
            fi
        done
    fi
fi
# vim:ts=4:sw=4

Created by swannie on 2003-02-19 17:32:11, modified by swannie on 2003-09-30 16:41:47.
Modify Page

Home > Linux > Scripts-n-Stuff > Neat-o prompts...

Hosting for this website generously provided by Narnia Pet Behavior and Training, Inc. Page dynamically created using PHP, page last modified on November 05, 2003 11:00:16.
All images and texts contained herin are © Copyright 1995-2010 swannie.net, and Brian R. Swan unless noted otherwise. All rights reserved.