-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.

5
  • Why am I getting negative votes? Commented Jan 5, 2014 at 3:11
  • 1
    Because if you searched this site you'd find your answer. unix.stackexchange.com/questions/35777/… Commented Jan 5, 2014 at 3:57
  • @slm The question you link does not explicitly ask for the colored output. Commented Jan 5, 2014 at 9: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 answer is also useful. Commented Jan 5, 2014 at 9:51
  • @Bernhard - my point still stands, search this site, prompts is pretty well covered. Commented Jan 5, 2014 at 13:03

1 Answer 1

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$ " 
1
  • Testing this on a mac, I needed to change setf to setaf. Commented Jan 5, 2014 at 5:01

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.