From 2cec6490e26d476f354cb1ee2bbef73ab94e8823 Mon Sep 17 00:00:00 2001
From: Grigory Petrov <grigory.v.p@gmail.com>
Date: Wed, 26 Aug 2015 14:47:03 +0300
Subject: bash prompt length fix: zero-length chars must be placed between \[
 and \], but only for PS1 string

---
 prompt.bash   |  8 ++++----
 radar-base.sh | 24 ++++++++++++------------
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/prompt.bash b/prompt.bash
index d577087..4ceaf22 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;30mgit:(\033[0m"
+  printf " \[\033[1;30m\]git:(\[\033[0m\]"
   bash_color_remote_commits
-  printf "\033[0;37m"
+  printf "\[\033[0;37m\]"
   readable_branch_name
-  printf "\033[0m"
+  printf "\[\033[0m\]"
   bash_color_local_commits
-  printf "\033[1;30m)\033[0m"
+  printf "\[\033[1;30m\])\[\033[0m\]"
   bash_color_changes_status
 fi
diff --git a/radar-base.sh b/radar-base.sh
index 787d7a5..63b2b98 100755
--- a/radar-base.sh
+++ b/radar-base.sh
@@ -305,11 +305,11 @@ bash_color_changes_status() {
   local changes=""
 
   if [[ -n "$porcelain" ]]; then
-    local green_staged_prefix="\033[1;32m"
-    local red_unstaged_prefix="\033[1;31m"
-    local yellow_conflicted_prefix="\033[1;33m"
-    local grey_untracked_prefix="\033[1;37m"
-    local reset_suffix="\033[0m"
+    local green_staged_prefix="\[\033[1;32m\]"
+    local red_unstaged_prefix="\[\033[1;31m\]"
+    local yellow_conflicted_prefix="\[\033[1;33m\]"
+    local grey_untracked_prefix="\[\033[1;37m\]"
+    local reset_suffix="\[\033[0m\]"
 
     local staged_changes="$(staged_status "$porcelain" "$green_staged_prefix" "$reset_suffix")"
     local unstaged_changes="$(unstaged_status "$porcelain" "$red_unstaged_prefix" "$reset_suffix")"
@@ -377,9 +377,9 @@ zsh_color_changes_status() {
 bash_color_local_commits() {
   local separator="${1:- }"
 
-  local green_ahead_arrow="\033[1;32m↑\033[0m"
-  local red_behind_arrow="\033[1;31m↓\033[0m"
-  local yellow_diverged_arrow="\033[1;33m⇵\033[0m"
+  local green_ahead_arrow="\[\033[1;32m\]↑\[\033[0m\]"
+  local red_behind_arrow="\[\033[1;31m\]↓\[\033[0m\]"
+  local yellow_diverged_arrow="\[\033[1;33m\]⇵\[\033[0m\]"
 
   local local_commits=""
   if remote_branch="$(remote_branch_name)"; then
@@ -422,10 +422,10 @@ zsh_color_local_commits() {
 
 bash_color_remote_commits() {
   local remote_master="\xF0\x9D\x98\xAE" # an italic m to represent master
-  local green_ahead_arrow="\033[1;32m←\033[0m"
-  local red_behind_arrow="\033[1;31m→\033[0m"
-  local yellow_diverged_arrow="\033[1;33m⇄\033[0m"
-  local not_upstream="\033[1;31m⚡\033[0m"
+  local green_ahead_arrow="\[\033[1;32m\]←\[\033[0m\]"
+  local red_behind_arrow="\[\033[1;31m\]→\[\033[0m\]"
+  local yellow_diverged_arrow="\[\033[1;33m\]⇄\[\033[0m\]"
+  local not_upstream="\[\033[1;31m\]⚡\[\033[0m\]"
 
   if remote_branch="$(remote_branch_name)"; then
     remote_ahead="$(remote_ahead_of_master "$remote_branch")"
-- 
cgit v1.2.3