1

I created a nice PS1 for bash with http://bashrcgenerator.com/, but something seems to go wrong. The terminal emulator shows me some random, characters which means that PS1 probably has a syntax error. The weird thing is that it will work after I edit it (with nano). If I add a space, remove it, save it, and run bash, it works fine. But when I log out and log in agai,n it's buggy and weird again. This is my .bashrc:

#
# ~/.bashrc
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

alias ls='ls --color=auto'

#PS1='[\u@\h \W]\$ '
PS1="\[$(tput sgr0)\]\033[38;5;15m\033[38;5;14m\u\[$(tput sgr0)\]\033[38;5;15m\033[38;5;15m \[$(tput sgr0)\]\033[38;5;15m\033[38;5;10m\w\[$(tput sgr0)\]\033[38;5;15m\033[38;5;15m \
\[$(tput sgr0)\]\033[38;5;15m\033[38;5;14m\\$\[$(tput sgr0)\]\033[38;5;15m\033[38;5;15m \[$(tput sgr0)\]"
Sildoreth
  • 1,884

1 Answers1

2

I recommend just manually creating the prompt yourself. All you have to do is set up a few variables, and then your code for setting the prompt becomes readable. In my bashrc file, I have this:

#Set variables for foreground colors
fgRed=$(tput setaf 1)     ; fgGreen=$(tput setaf 2)  ; fgBlue=$(tput setaf 4)
fgMagenta=$(tput setaf 5) ; fgYellow=$(tput setaf 3) ; fgCyan=$(tput setaf 6)
fgWhite=$(tput setaf 7)   ; fgBlack=$(tput setaf 0)
#Set variables for background colors
bgRed=$(tput setab 1)     ; bgGreen=$(tput setab 2)  ; bgBlue=$(tput setab 4)
bgMagenta=$(tput setab 5) ; bgYellow=$(tput setab 3) ; bgCyan=$(tput setab 6)
bgWhite=$(tput setab 7)   ; bgBlack=$(tput setab 0)
#Set variables for font weight and text decoration
B=$(tput bold) ; U=$(tput smul) ; C=$(tput sgr0)
#NOTE: ${C} clears the current formatting

PS1="${B}${fgCyan}\u${C}@\h(bash): ${fgGreen}\w${C} > "

I'll bet you can tell at a quick glance what my prompt looks like. And that's the point; no fancy WYSIWYG editors are required.

The reason I use tput is that it's supposed to be more portable. And as an added bonus, using tput makes it so that when you type echo $PS1 at the command prompt, it'll show you a formatted/colorized version of PS1.

This doesn't exactly answer why yours isn't working. But if you set up your prompt like this, you will definitely be able to get rid of that pesky error.

Sildoreth
  • 1,884
  • That's actually a good idea. Writing it myself is much cleaner than that unreadable WYSIWYG thing anyway. I was just trying (and failing) to be lazy. – Wietse de Vries May 18 '15 at 21:48