-3

I would like to learn how to make my shell look like this:

[user@host ~/Folder]
$

instead of (the default):

[user@host ~/Folder]$.

Also, I'd like to have color on user@host and Folder. How can I do this?

Note: This prompt is my model.

  • Why am I getting negative votes? – Eric Aldana Jan 05 '14 at 03:11
  • 1
    Because if you searched this site you'd find your answer. http://unix.stackexchange.com/questions/35777/how-to-change-the-prompt-in-linux – slm Jan 05 '14 at 03:57
  • @slm The question you link does not explicitly ask for the colored output. – Bernhard Jan 05 '14 at 09:37
  • In fact if you searched google you would find an answer. Try "How do I change bash prompt" and read any of the results. [This](http://unix.stackexchange.com/a/150/22222) answer is also useful. – terdon Jan 05 '14 at 09:51
  • @Bernhard - my point still stands, search this site, prompts is pretty well covered. – slm Jan 05 '14 at 13:03

1 Answers1

0

Here's a script that I personally use:

###
### Set the prompting to my liking
###

    # Save the old prompt

OLD_PS1="$PS1"

    # Put the "non-printing" characters between \[ and \] for the prompt so
    #  that the shell can properly determine the length of the prompt.

if [ -z "$TERM" ] || [ "$TERM" = "dumb" ]
then
    BOLD=""
    NORM=""
    BLUE=""
    BLACK=""
    RED=""
else
    BOLD="\\[$(tput bold)\\]"
    NORM="\\[$(tput sgr0)\\]"
    BLUE="\\[$(tput setf 1)\\]"
    BLACK="\\[$(tput setf 0)\\]"
    RED="\\[$(tput setf 4)\\]"
fi

PS1="$NORM"'\n'"$BOLD"'\w'"$NORM"'\n'"$BLUE"'\u@\h, $?>'"$NORM"' '

    # For use with set_prompt_comment:
BASE_PS1="$PS1"


##
##
##

set_prompt_comment ()
{
    typeset comments

    if [ -z "$BASE_PS1" ]
    then
        echo "Need BASE_PS1 to be defined to proceed!" >&2
    else
        comments="$*"

        if [ -z "$comments" ]
        then
            PS1="$BASE_PS1"
        else
            PS1="\\n${RED}${comments}${BASE_PS1}"
        fi
    fi
}

Working with this, the following may give what you want:

PS1="[${RED}user@host${NORM} ${BLUE}~/Folder${NORM}]\\n$ "
ash
  • 7,120
  • 2
  • 18
  • 12