From 11e8ad4bdce9979eb871635bf455213788de5e05 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Wed, 26 Aug 2015 13:39:39 +0100 Subject: Bypass PS1s conversion of \[ In PS1 you need to escape non-printing characters, like the color codes. The standard way is wrapping it in `\[` and `\]`. But for a dynamic prompt, i.e. one that renders the results of a function every time the prompt renders, that `\[` will be output as literals. To fix this we bypass the conversion and wrap our non-printing characters in the desired characters directly: `\[` -> `\x01` `\]` -> `\x02` --- prompt.bash | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'prompt.bash') diff --git a/prompt.bash b/prompt.bash index 4ceaf22..4821319 100755 --- a/prompt.bash +++ b/prompt.bash @@ -4,12 +4,12 @@ dot="$(cd "$(dirname "$0")"; pwd)" source "$dot/radar-base.sh" if is_repo; then - printf " \[\033[1;30m\]git:(\[\033[0m\]" + printf " \x01\033[1;30m\x02git:(\x01\033[0m\x02" bash_color_remote_commits - printf "\[\033[0;37m\]" + printf "\x01\033[0;37m\x02" readable_branch_name - printf "\[\033[0m\]" + printf "\x01\033[0m\x02" bash_color_local_commits - printf "\[\033[1;30m\])\[\033[0m\]" + printf "\x01\033[1;30m\x02)\x01\033[0m\x02" bash_color_changes_status fi -- cgit v1.2.3