git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Fix early wrapping when using bash with git-prompt.sh

From
Richard Quadling <rquadling@gmail.com>
Date
Mar 11, 2024, 14:05 UTC
Message-ID
<CAKUjMCXik2565fok+z9=43DUcigbfqpWAEM-rfnO0rN=gS-Okw@mail.gmail.com>
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 71f179cba3..6585164efe 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -259,10 +259,10 @@ __git_ps1_colorize_gitstring ()
  else
  # Using \001 and \002 around colors is necessary to prevent
  # issues with command line editing/browsing/completion!
- local c_red=$'\001\e[31m\002'
- local c_green=$'\001\e[32m\002'
- local c_lblue=$'\001\e[1;34m\002'
- local c_clear=$'\001\e[0m\002'
+ local c_red=$'\\001\e[31m\\002'
+ local c_green=$'\\001\e[32m\\002'
+ local c_lblue=$'\\001\e[1;34m\\002'
+ local c_clear=$'\\001\e[0m\\002'
  fi
  local bad_color=$c_red
  local ok_color=$c_green
diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index d667dda654..fc6fdd36c6 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -13,10 +13,10 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 . "$GIT_BUILD_DIR/contrib/completion/git-prompt.sh"

 actual="$TRASH_DIRECTORY/actual"
-c_red='\001\e[31m\002'
-c_green='\001\e[32m\002'
-c_lblue='\001\e[1;34m\002'
-c_clear='\001\e[0m\002'
+c_red='\\001\e[31m\\002'
+c_green='\\001\e[32m\\002'
+c_lblue='\\001\e[1;34m\\002'
+c_clear='\\001\e[0m\\002'

 test_expect_success 'setup for prompt tests' '
  git init otherrepo &&
Message 1 of 1 in “Fix early wrapping when using bash with git-prompt.sh”
  1. Richard QuadlingMar 11, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.