From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ramkumar Ramachandra Subject: [PATCH v2] git-prompt.sh: colorize ZSH prompt Date: Sun, 12 May 2013 03:48:59 +0530 Message-ID: <1368310739-24099-1-git-send-email-artagnon@gmail.com> References: Cc: Felipe Contreras , Junio C Hamano To: Git List X-From: git-owner@vger.kernel.org Sun May 12 00:18:45 2013 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UbI7n-00031d-RA for gcvg-git-2@plane.gmane.org; Sun, 12 May 2013 00:18:44 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754542Ab3EKWS2 (ORCPT ); Sat, 11 May 2013 18:18:28 -0400 Received: from mail-pd0-f176.google.com ([209.85.192.176]:42252 "EHLO mail-pd0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754482Ab3EKWS1 (ORCPT ); Sat, 11 May 2013 18:18:27 -0400 Received: by mail-pd0-f176.google.com with SMTP id x10so3546038pdj.35 for ; Sat, 11 May 2013 15:18:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=UhOCVTAcGOSCslfMDvXS3uZTBREUk8JGaIVgKP1nUjA=; b=ReDRw7ROz8N+68/MDQGjtd5zREZPW7UEJ2FxfBNtH8MTjmuZmSTDZy8rha1g/GdqKc FcdrIsCVukMgegAM0ERRayedu5v0Yf++5ksUefU8v55+xPViexYCEoSBqqjFuodnCwsh XV4fa8ZBKeFiL4fwhThGlCQM/rj9BUp2ZF/C54tQY8KCj8cvyjglZA2hVcD45bmzFxV8 j4qyAux/Bdl5xjOkxT+w8YD71jeoFYT+jyn7vnsGsHpc4KbabiIT+vgnF8KWCc6Zq4/z 9ZpVVCoL49Ovn4waSMP/Qx9HwFNSOKqicOPLSKjMMtF2cbzysJ2bC/N+oVGqNkjWxHXM lt8g== X-Received: by 10.68.164.98 with SMTP id yp2mr22637721pbb.214.1368310706734; Sat, 11 May 2013 15:18:26 -0700 (PDT) Received: from localhost.localdomain ([122.174.27.160]) by mx.google.com with ESMTPSA id vu10sm7848476pbc.27.2013.05.11.15.18.24 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 11 May 2013 15:18:25 -0700 (PDT) X-Mailer: git-send-email 1.8.3.rc1.46.gfc3cab0 In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Add colors suitable for use in the ZSH prompt. Having learnt that the ZSH equivalent of PROMPT_COMMAND is precmd (), you can now use GIT_PS1_SHOWCOLORHINTS with ZSH. Signed-off-by: Ramkumar Ramachandra --- You like this more? I don't mind going either way. contrib/completion/git-prompt.sh | 67 ++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 20 deletions(-) diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh index 08c9b22..26e5bc2 100644 --- a/contrib/completion/git-prompt.sh +++ b/contrib/completion/git-prompt.sh @@ -20,7 +20,8 @@ # , which are strings you would put in $PS1 before # and after the status string generated by the git-prompt # machinery. e.g. -# PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "' +# Bash: PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "' +# ZSH: precmd () { __git_ps1 "%n" ":%~$ " "|%s" } # will show username, at-sign, host, colon, cwd, then # various status string, followed by dollar and SP, as # your prompt. @@ -363,10 +364,18 @@ __git_ps1 () if [ $pcmode = yes ]; then local gitstring= if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then - local c_red='\e[31m' - local c_green='\e[32m' - local c_lblue='\e[1;34m' - local c_clear='\e[0m' + if [[ -n ${ZSH_VERSION-} ]]; then + local c_red='%F{red}' + local c_green='%F{green}' + local c_lblue='%F{blue}' + local c_clear='%f' + else + local c_red='\e[31m' + local c_green='\e[32m' + local c_lblue='\e[1;34m' + local c_clear='\e[0m' + fi + local bad_color=$c_red local ok_color=$c_green local branch_color="$c_clear" @@ -379,23 +388,41 @@ __git_ps1 () branch_color="$bad_color" fi - # Setting gitstring directly with \[ and \] around colors - # is necessary to prevent wrapping issues! - gitstring="\[$branch_color\]$branchstring\[$c_clear\]" + if [[ -n ${ZSH_VERSION-} ]]; then + gitstring="$branch_color$branchstring$c_clear" - if [ "$w" = "*" ]; then - gitstring="$gitstring\[$bad_color\]$w" - fi - if [ -n "$i" ]; then - gitstring="$gitstring\[$ok_color\]$i" - fi - if [ -n "$s" ]; then - gitstring="$gitstring\[$flags_color\]$s" - fi - if [ -n "$u" ]; then - gitstring="$gitstring\[$bad_color\]$u" + if [ "$w" = "*" ]; then + gitstring="$gitstring$bad_color$w" + fi + if [ -n "$i" ]; then + gitstring="$gitstring$ok_color$i" + fi + if [ -n "$s" ]; then + gitstring="$gitstring$flags_color$s" + fi + if [ -n "$u" ]; then + gitstring="$gitstring$bad_color$u" + fi + gitstring="$gitstring$c_clear$r$p" + else + # Setting gitstring directly with \[ and \] around colors + # is necessary to prevent wrapping issues! + gitstring="\[$branch_color\]$branchstring\[$c_clear\]" + + if [ "$w" = "*" ]; then + gitstring="$gitstring\[$bad_color\]$w" + fi + if [ -n "$i" ]; then + gitstring="$gitstring\[$ok_color\]$i" + fi + if [ -n "$s" ]; then + gitstring="$gitstring\[$flags_color\]$s" + fi + if [ -n "$u" ]; then + gitstring="$gitstring\[$bad_color\]$u" + fi + gitstring="$gitstring\[$c_clear\]$r$p" fi - gitstring="$gitstring\[$c_clear\]$r$p" else gitstring="$c${b##refs/heads/}${f:+$f}$r$p" fi -- 1.8.3.rc1.46.gfc3cab0