My Bash prompt (based on mike kasberg's) generally works fine. But when I get an error code, and then write over to the next line, no newline is generated, so the text goes back over my previous prompt.
Code in question:
# gets error code
__mkps1_inject_exitcode() {
local code=$1
local bg_red='\033[41m'
local white='\033[37m'
local red='\033[31m'
if [ "$code" -ne "0" ]; then
echo -e " ${bg_red}${white} $code${red}"
fi
}
__mkps1_exitcode() {
# We need to run a function at runtime to evaluate the exitcode.
echo "\$(__mkps1_inject_exitcode \$?)"
}
PROMPT_COMMAND='__git_ps1 "${yellow}\u ${bg_grey}${black} $(__pwd_fancy)${grey}" "$(__mkps1_exitcode) ${reset_bg}${reset} " " ${bg_blue}${bold}${black}${bg_blue} %s${unbold}${blue}"'
I've been tinkering with this for a while, so the problems that have come up vary. Sometimes, the newline works fine, but when I try to go back to the previous line (ctrl+left arrow), I can't, or I end up deleting the text of the previous prompt, or something weird. I'm sure this is a problem with escaping the color codes, since similar issues are scattered all around this stack exchange. But if I surround the colors in \[...\]
the brackets show up in the prompt. I'm not sure where my weak link is, and would really appreciate some help!
__git_ps1
,__pwd_fancy
and other things you did not define in the snippet. Shall we take them from the external site you linked to? They are not behind the link and we are not going to search the entire project. Your question should be standalone, please edit and make it so.