I am using bash in os X Terminal app, and my custom $PS1 breaks when I scroll through my history.
PS1="${BLUE}\u${CYAN}@${RED}\h${BLUE}\w\n\[${red}\$${NC}\]"
also tried PS1="${BLUE}\u${CYAN}@${RED}\h${BLUE}\w\r\n[${red}\$${NC}]"
The problem seems to be in the newline. I have used this bash prompt on Slackware no prob.
But default value for PS1 in Mac OS is set in /etc/bashrc . It's done conditionally--i.e if PS1 exists (it's a login shell) then PS1 is assigned a value.
export is used to set environment variable in operating system. This variable will be available to all child processes created by current Bash process ever after. PS1 is the primary prompt which is displayed before each command, thus it is the one most people customize.
You need the [ and ] arond every escape sequence; do $BLUE and the like include these? If not, they need to be bracketed with these calls.
To avoid such 'escaping' difficulties as you prompt needs evole to be more complex, this should be a skeleton to start growing on:
function _my_prompt ()
{
# magic goes here
my_prmpt=....
}
PROMPT_COMMAND='_my_prompt'
PS1="[\$my_prmpt] \$"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With