After solving the first issue with my custom prompt I still have another one left.
When I cycle through my last used commands via the arrow-up and arrow-down keys I will sometimes have some characters from a previous command stay visible although the are not accessible nor actually in the commandline. They are just a visual bug very annoying and confusing.
Here I went a bit up in the command history and then back down to the current (empty) prompt and typed echo. the pip i (coming from a previous pip install command) is not accessible with my cursor. It's visible there but not actually existent.
My .bashrc has this code for customizing the prompt:
set_PS1()
{
local Reset="\\[$(tput sgr0 )\\]"
local Bold="\\[$(tput bold )\\]"
local Red="\\[$(tput setaf 1 )\\]"
local Green="\\[$(tput setaf 2 )\\]"
local Yellow="\\[$(tput setaf 3 )\\]"
local Blue="\\[$(tput setaf 4 )\\]"
local MagentaBG="\\[$(tput setab 5 )\\]"
local Cyan="\\[$(tput setaf 6 )\\]"
local Whoami='\u'
local Where='\w'
local Hostname='\h'
local Time='\D{%H:%M:%S}'
local Exit_Code="$?"
exit_code_prompt() {
local Exit_Code="$?"
local Red="$(tput setaf 1 )"
local Green="$(tput setaf 2 )"
if (($Exit_Code == 0 )); then
printf '%s\xE2\x9C\x93 \xE2\x86\x92 ' "$Green" # Green checkmark symbol
else
printf '%s\xE2\x9C\x98 %s \xE2\x86\x92 ' "$Red" "$Exit_Code" # Red cross mark symbol and exit code
fi
}
local Line_1="$Bold$Yellow$Time $Cyan$Whoami$Blue@$Cyan$Hostname$Reset$Bold":" $Blue$Where$Reset"
local Line_2="$Bold\$(exit_code_prompt)$Reset$Bold \$: $Reset"
#local Line_2="$Bold \$: $Reset"
PS1="$Line_1\n$Line_2"
unset -f set_PS1
}
set_PS1
I already narrowed the problem down to the exit_code_prompt function since the problem doesn't appear if I remove it from $Line_2
EDIT: When I put the color definitions inside of the function into brackets like on the outside like this:
exit_code_prompt() {
local Exit_Code="$?"
local Red="\\[$(tput setaf 1 )\\]"
local Green="\\[$(tput setaf 2 )\\]"
if (($Exit_Code == 0 )); then
printf '%s\xE2\x9C\x93 \xE2\x86\x92 ' "$Green" # Green checkmark symbol
else
printf '%s\xE2\x9C\x98 %s \xE2\x86\x92 ' "$Red" "$Exit_Code" # Red cross mark symbol and exit code
fi
}
I get this result:
Same result if I put only single backslashes \
Plus the inital problem is still there!





