From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ramkumar Ramachandra Subject: [PATCH 3/3] prompt: colorize ZSH prompt Date: Fri, 17 May 2013 14:25:48 +0530 Message-ID: <1368780948-28917-4-git-send-email-artagnon@gmail.com> References: <1368780948-28917-1-git-send-email-artagnon@gmail.com> Cc: Git List To: Junio C Hamano X-From: git-owner@vger.kernel.org Fri May 17 10:54:32 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 1UdGQi-0000XC-SJ for gcvg-git-2@plane.gmane.org; Fri, 17 May 2013 10:54:25 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755457Ab3EQIyT (ORCPT ); Fri, 17 May 2013 04:54:19 -0400 Received: from mail-pb0-f42.google.com ([209.85.160.42]:52806 "EHLO mail-pb0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755461Ab3EQIyR (ORCPT ); Fri, 17 May 2013 04:54:17 -0400 Received: by mail-pb0-f42.google.com with SMTP id up7so3111483pbc.29 for ; Fri, 17 May 2013 01:54:16 -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=LBhBC7Gd3bZvRhj8ZgPYr8PLN/YF0koQexHfFwzLHbo=; b=noKuMgWuDYNFvjeLVs8fUxEB7zF9acjjhpc2XmZYykQ9UNb0xp0pqMr9h3aKGBK+95 X3J1+lrpuUxdyhvdQPeuxRNdhveTLQ2dNPBnAJyarw4ZOdBRso51UDRu8LQnWS4DcrUI G+naJws7VkpG1g1snKvtMzDi5OZ6fWqxaN/MFJ8NA24uNiHvXX8CnX3ijiLcugtB9D4P mFnz8Apva0LHSqjls/0nD+5fOBNIXJ6IrF7Ud8BPjMzdeMaRQip4TfricTewq9ttLgIq zPB6dHG1kIctVNSVeGFCu9arGX6X10GXR0b8nWmShCrn5jr+ruTcNPfDm0wxVJVsw5Qi rWIw== X-Received: by 10.67.5.168 with SMTP id cn8mr48560331pad.119.1368780856484; Fri, 17 May 2013 01:54:16 -0700 (PDT) Received: from luneth.maa.corp.collab.net ([182.71.239.158]) by mx.google.com with ESMTPSA id do4sm10438933pbc.8.2013.05.17.01.54.14 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 17 May 2013 01:54:15 -0700 (PDT) X-Mailer: git-send-email 1.8.1.2.432.g070c57d In-Reply-To: <1368780948-28917-1-git-send-email-artagnon@gmail.com> 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 --- contrib/completion/git-prompt.sh | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh index 263d2d7..92f2770 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. @@ -227,6 +228,43 @@ __git_ps1_show_upstream () # places. __git_ps1_colorize_gitstring () { + if [[ -n ${ZSH_VERSION-} ]]; then + local c_red='%F{red}' + local c_green='%F{green}' + local c_lblue='%F{blue}' + local c_clear='%f' + local bad_color=$c_red + local ok_color=$c_green + local branch_color="$c_clear" + local flags_color="$c_lblue" + local branchstring="$c${b##refs/heads/}" + + if [ $detached = no ]; then + branch_color="$ok_color" + else + branch_color="$bad_color" + fi + + gitstring="$branch_color$branchstring$c_clear" + + if [ -n "$w$i$s$u$r$p" ]; then + gitstring="$gitstring$z" + fi + 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" + return + fi local c_red='\e[31m' local c_green='\e[32m' local c_lblue='\e[1;34m' -- 1.8.1.2.432.g070c57d