Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am accessing two of my Pis via a serial connection on pins 8 and 10. One of them uses a serial to USB connector for my Mac and the other uses an HC-06 which connects to my Android. The console/terminal over serial is very bland and colorless, unlike the ssh console/terminal which, by default, has a bolded and green hostname as well as a bolded and blueish working directory.

I know that it is possible for the serial pins to relay color in the command line, as grep still returns it's results nicely highlighted in red.

How can I get the hostname and working directory to be their colorful selves again?

share|improve this question
    
If you are partial to color in the terminal and more dynamic completion mechanisms than bash, I'd recommend the fish shell (that bit about "a command line shell for the 90s" is a joke, since it was first released 10 years ago). Its scripting language is not POSIX but as a default interactive shell it is definitely nicer, once you get the hang of things. I use it on the pi and it is fine over ssh; Raspbian has a package (apt-get install fish, then try it with fish). – goldilocks Jan 10 at 13:50
up vote 3 down vote accepted

The default bash prompt is set in a system wide file; for a complete explanation of how bash sources its configuration see INVOCATION near the top of man bash. In short, that system wide file is sourced by ~/.bashrc; it is pretty obvious.

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

Evidentally, what's deciding about the prompt is making the wrong decision. You could dig into that and try to override it by pre-setting some variable, but I recommend against fiddling with /etc/bashrc and instead simply define your own prompt after that sourcing in ~/bashrc.

If you search online for bash prompt you will find copious discussions of it, such as the TLDP How-to. There are actually 4 prompts (see man bash again) but the standard one is defined by PS1. This respects standard ANSI escapes; for an explanation of the potential color codes see here. It also uses special escapes to signify things such as the current working directory, user and host name, etc. Those are all defined under PROMPTING in man bash. An example:

export TERM=xterm-256color
export PS1="\[\033[1;38;5;196m\]\h\[\033[1;48;5;11;38;5;17m\]\u\[\033[0;32m\]\w\[\033[0m\]: "

Gives me:

  • Hostname (\h) in bold bright red.
  • Username (\u) in bold dark blue on bright yellow.
  • Current working directory (\w) in green

But your mileage may vary (in fact, I think the usename bg/fg should be the other way around?). Anyway, it may take a few minutes fooling around; once you've settled on something put it at the end of ~/.bashrc and it should apply everywhere 24/7.

You can include newlines (\n) in a prompt, BTW, which is useful if they are long or include the cwd path.

share|improve this answer

Just add:

export PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]\w \$\[\033[00m\] '

at the bottom of ~/.bashrc

share|improve this answer

This has nothing to do with using the serial pins to relay color (that type of analog system went by the wayside long ago).

This has everything to do with terminal type.

When connecting using SSH, the default term type is usually something like xterm or xterm-color. When connecting using a serial port to a console the term type is likely to be something does not indicate that it supports ANSI color (older terminals only supported monochrome, settings colors like you want is a later addition).

Check your TERM (term) type from each login. Then change the console one (or hard code in your .profile)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.