{"thread":{"id":"33847","subject":"[PATCH v3 0/3] Colored prompt for ZSH","startedAt":"2013-05-17T08:55:45Z","lastAt":"2013-05-17T17:00:51Z","messageCount":5,"participants":["Ramkumar Ramachandra","Junio C Hamano"],"isPatch":true,"patchVersion":3,"patchTotal":3},"messages":[{"id":"217682","messageId":"1368780948-28917-1-git-send-email-artagnon@gmail.com","threadId":"33847","inReplyTo":null,"subject":"[PATCH v3 0/3] Colored prompt for ZSH","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-05-17T08:55:45Z","receivedAt":"2013-05-17T08:55:45Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"One minor change, in accordance with Junio's review.  In part 1, I\nuse:\n\nlocal z=\"${GIT_PS1_STATESEPARATOR-\" \"}\"\n\nInstead of the convoluted:\n\nlocal z=\" \"\nif [ -n \"${GIT_PS1_STATESEPARATOR+set}\" ]; then\n\tz=\"${GIT_PS1_STATESEPARATOR}\"\nfi\n\nEverything else is the same.  I've rebased it on top of the latest\n`master`.\n\nRamkumar Ramachandra (3):\n  prompt: introduce GIT_PS1_STATESEPARATOR\n  prompt: factor out gitstring coloring logic\n  prompt: colorize ZSH prompt\n\n contrib/completion/git-prompt.sh | 124 +++++++++++++++++++++++++++------------\n 1 file changed, 85 insertions(+), 39 deletions(-)\n\n-- \n1.8.1.2.432.g070c57d\n"},{"id":"217683","messageId":"1368780948-28917-2-git-send-email-artagnon@gmail.com","threadId":"33847","inReplyTo":"1368780948-28917-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 1/3] prompt: introduce GIT_PS1_STATESEPARATOR","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-05-17T08:55:46Z","receivedAt":"2013-05-17T08:55:46Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"A typical prompt looks like:\n\n    artagnon|master *=:~/src/git$\n                   ^\n                   why do we have this space?\n\nNobody has branch names that end with +, *, =, < or > anyway, so it\ndoesn't serve the purpose of disambiguation.\n\nMake this separator configurable via GIT_PS1_STATESEPARATOR.  This means\nthat you can set it to \"\" and get this prompt:\n\n    artagnon|master*=:~/src/git$\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n contrib/completion/git-prompt.sh | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex eaf5c36..fb9296b 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -359,6 +359,7 @@ __git_ps1 ()\n \t\t\tfi\n \t\tfi\n \n+\t\tlocal z=\"${GIT_PS1_STATESEPARATOR-\" \"}\"\n \t\tlocal f=\"$w$i$s$u\"\n \t\tif [ $pcmode = yes ]; then\n \t\t\tlocal gitstring=\n@@ -384,7 +385,7 @@ __git_ps1 ()\n \t\t\t\tgitstring=\"\\[$branch_color\\]$branchstring\\[$c_clear\\]\"\n \n \t\t\t\tif [ -n \"$w$i$s$u$r$p\" ]; then\n-\t\t\t\t\tgitstring=\"$gitstring \"\n+\t\t\t\t\tgitstring=\"$gitstring$z\"\n \t\t\t\tfi\n \t\t\t\tif [ \"$w\" = \"*\" ]; then\n \t\t\t\t\tgitstring=\"$gitstring\\[$bad_color\\]$w\"\n@@ -400,13 +401,13 @@ __git_ps1 ()\n \t\t\t\tfi\n \t\t\t\tgitstring=\"$gitstring\\[$c_clear\\]$r$p\"\n \t\t\telse\n-\t\t\t\tgitstring=\"$c${b##refs/heads/}${f:+ $f}$r$p\"\n+\t\t\t\tgitstring=\"$c${b##refs/heads/}${f:+$z$f}$r$p\"\n \t\t\tfi\n \t\t\tgitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n \t\t\tPS1=\"$ps1pc_start$gitstring$ps1pc_end\"\n \t\telse\n \t\t\t# NO color option unless in PROMPT_COMMAND mode\n-\t\t\tprintf -- \"$printf_format\" \"$c${b##refs/heads/}${f:+ $f}$r$p\"\n+\t\t\tprintf -- \"$printf_format\" \"$c${b##refs/heads/}${f:+$z$f}$r$p\"\n \t\tfi\n \tfi\n }\n-- \n1.8.1.2.432.g070c57d\n"},{"id":"217684","messageId":"1368780948-28917-3-git-send-email-artagnon@gmail.com","threadId":"33847","inReplyTo":"1368780948-28917-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 2/3] prompt: factor out gitstring coloring logic","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-05-17T08:55:47Z","receivedAt":"2013-05-17T08:55:47Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"So that we can extend it with ZSH-colors in a later patch.\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n contrib/completion/git-prompt.sh | 79 ++++++++++++++++++++++------------------\n 1 file changed, 43 insertions(+), 36 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex fb9296b..263d2d7 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -222,6 +222,48 @@ __git_ps1_show_upstream ()\n \n }\n \n+# Helper function that is meant to be called from __git_ps1.  It\n+# builds up a gitstring injecting color codes into the appropriate\n+# places.\n+__git_ps1_colorize_gitstring ()\n+{\n+\tlocal c_red='\\e[31m'\n+\tlocal c_green='\\e[32m'\n+\tlocal c_lblue='\\e[1;34m'\n+\tlocal c_clear='\\e[0m'\n+\tlocal bad_color=$c_red\n+\tlocal ok_color=$c_green\n+\tlocal branch_color=\"$c_clear\"\n+\tlocal flags_color=\"$c_lblue\"\n+\tlocal branchstring=\"$c${b##refs/heads/}\"\n+\n+\tif [ $detached = no ]; then\n+\t\tbranch_color=\"$ok_color\"\n+\telse\n+\t\tbranch_color=\"$bad_color\"\n+\tfi\n+\n+\t# Setting gitstring directly with \\[ and \\] around colors\n+\t# is necessary to prevent wrapping issues!\n+\tgitstring=\"\\[$branch_color\\]$branchstring\\[$c_clear\\]\"\n+\n+\tif [ -n \"$w$i$s$u$r$p\" ]; then\n+\t\tgitstring=\"$gitstring$z\"\n+\tfi\n+\tif [ \"$w\" = \"*\" ]; then\n+\t\tgitstring=\"$gitstring\\[$bad_color\\]$w\"\n+\tfi\n+\tif [ -n \"$i\" ]; then\n+\t\tgitstring=\"$gitstring\\[$ok_color\\]$i\"\n+\tfi\n+\tif [ -n \"$s\" ]; then\n+\t\tgitstring=\"$gitstring\\[$flags_color\\]$s\"\n+\tfi\n+\tif [ -n \"$u\" ]; then\n+\t\tgitstring=\"$gitstring\\[$bad_color\\]$u\"\n+\tfi\n+\tgitstring=\"$gitstring\\[$c_clear\\]$r$p\"\n+}\n \n # __git_ps1 accepts 0 or 1 arguments (i.e., format string)\n # when called from PS1 using command substitution\n@@ -364,42 +406,7 @@ __git_ps1 ()\n \t\tif [ $pcmode = yes ]; then\n \t\t\tlocal gitstring=\n \t\t\tif [ -n \"${GIT_PS1_SHOWCOLORHINTS-}\" ]; then\n-\t\t\t\tlocal c_red='\\e[31m'\n-\t\t\t\tlocal c_green='\\e[32m'\n-\t\t\t\tlocal c_lblue='\\e[1;34m'\n-\t\t\t\tlocal c_clear='\\e[0m'\n-\t\t\t\tlocal bad_color=$c_red\n-\t\t\t\tlocal ok_color=$c_green\n-\t\t\t\tlocal branch_color=\"$c_clear\"\n-\t\t\t\tlocal flags_color=\"$c_lblue\"\n-\t\t\t\tlocal branchstring=\"$c${b##refs/heads/}\"\n-\n-\t\t\t\tif [ $detached = no ]; then\n-\t\t\t\t\tbranch_color=\"$ok_color\"\n-\t\t\t\telse\n-\t\t\t\t\tbranch_color=\"$bad_color\"\n-\t\t\t\tfi\n-\n-\t\t\t\t# Setting gitstring directly with \\[ and \\] around colors\n-\t\t\t\t# is necessary to prevent wrapping issues!\n-\t\t\t\tgitstring=\"\\[$branch_color\\]$branchstring\\[$c_clear\\]\"\n-\n-\t\t\t\tif [ -n \"$w$i$s$u$r$p\" ]; then\n-\t\t\t\t\tgitstring=\"$gitstring$z\"\n-\t\t\t\tfi\n-\t\t\t\tif [ \"$w\" = \"*\" ]; then\n-\t\t\t\t\tgitstring=\"$gitstring\\[$bad_color\\]$w\"\n-\t\t\t\tfi\n-\t\t\t\tif [ -n \"$i\" ]; then\n-\t\t\t\t\tgitstring=\"$gitstring\\[$ok_color\\]$i\"\n-\t\t\t\tfi\n-\t\t\t\tif [ -n \"$s\" ]; then\n-\t\t\t\t\tgitstring=\"$gitstring\\[$flags_color\\]$s\"\n-\t\t\t\tfi\n-\t\t\t\tif [ -n \"$u\" ]; then\n-\t\t\t\t\tgitstring=\"$gitstring\\[$bad_color\\]$u\"\n-\t\t\t\tfi\n-\t\t\t\tgitstring=\"$gitstring\\[$c_clear\\]$r$p\"\n+\t\t\t\t__git_ps1_colorize_gitstring\n \t\t\telse\n \t\t\t\tgitstring=\"$c${b##refs/heads/}${f:+$z$f}$r$p\"\n \t\t\tfi\n-- \n1.8.1.2.432.g070c57d\n"},{"id":"217685","messageId":"1368780948-28917-4-git-send-email-artagnon@gmail.com","threadId":"33847","inReplyTo":"1368780948-28917-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 3/3] prompt: colorize ZSH prompt","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-05-17T08:55:48Z","receivedAt":"2013-05-17T08:55:48Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Add colors suitable for use in the ZSH prompt.  Having learnt that the\nZSH equivalent of PROMPT_COMMAND is precmd (), you can now use\nGIT_PS1_SHOWCOLORHINTS with ZSH.\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n contrib/completion/git-prompt.sh | 40 +++++++++++++++++++++++++++++++++++++++-\n 1 file changed, 39 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 263d2d7..92f2770 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -20,7 +20,8 @@\n #        <post>, which are strings you would put in $PS1 before\n #        and after the status string generated by the git-prompt\n #        machinery.  e.g.\n-#           PROMPT_COMMAND='__git_ps1 \"\\u@\\h:\\w\" \"\\\\\\$ \"'\n+#        Bash: PROMPT_COMMAND='__git_ps1 \"\\u@\\h:\\w\" \"\\\\\\$ \"'\n+#        ZSH:  precmd () { __git_ps1 \"%n\" \":%~$ \" \"|%s\" }\n #        will show username, at-sign, host, colon, cwd, then\n #        various status string, followed by dollar and SP, as\n #        your prompt.\n@@ -227,6 +228,43 @@ __git_ps1_show_upstream ()\n # places.\n __git_ps1_colorize_gitstring ()\n {\n+\tif [[ -n ${ZSH_VERSION-} ]]; then\n+\t\tlocal c_red='%F{red}'\n+\t\tlocal c_green='%F{green}'\n+\t\tlocal c_lblue='%F{blue}'\n+\t\tlocal c_clear='%f'\n+\t\tlocal bad_color=$c_red\n+\t\tlocal ok_color=$c_green\n+\t\tlocal branch_color=\"$c_clear\"\n+\t\tlocal flags_color=\"$c_lblue\"\n+\t\tlocal branchstring=\"$c${b##refs/heads/}\"\n+\n+\t\tif [ $detached = no ]; then\n+\t\t\tbranch_color=\"$ok_color\"\n+\t\telse\n+\t\t\tbranch_color=\"$bad_color\"\n+\t\tfi\n+\n+\t\tgitstring=\"$branch_color$branchstring$c_clear\"\n+\n+\t\tif [ -n \"$w$i$s$u$r$p\" ]; then\n+\t\t\tgitstring=\"$gitstring$z\"\n+\t\tfi\n+\t\tif [ \"$w\" = \"*\" ]; then\n+\t\t\tgitstring=\"$gitstring$bad_color$w\"\n+\t\tfi\n+\t\tif [ -n \"$i\" ]; then\n+\t\t\tgitstring=\"$gitstring$ok_color$i\"\n+\t\tfi\n+\t\tif [ -n \"$s\" ]; then\n+\t\t\tgitstring=\"$gitstring$flags_color$s\"\n+\t\tfi\n+\t\tif [ -n \"$u\" ]; then\n+\t\t\tgitstring=\"$gitstring$bad_color$u\"\n+\t\tfi\n+\t\tgitstring=\"$gitstring$c_clear$r$p\"\n+\t\treturn\n+\tfi\n \tlocal c_red='\\e[31m'\n \tlocal c_green='\\e[32m'\n \tlocal c_lblue='\\e[1;34m'\n-- \n1.8.1.2.432.g070c57d\n"},{"id":"217727","messageId":"7v7gix1qyk.fsf@alter.siamese.dyndns.org","threadId":"33847","inReplyTo":"1368780948-28917-3-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 2/3] prompt: factor out gitstring coloring logic","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-05-17T17:00:51Z","receivedAt":"2013-05-17T17:00:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramkumar Ramachandra <artagnon@gmail.com> writes:\n\n> So that we can extend it with ZSH-colors in a later patch.\n>\n> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n> ---\n>  contrib/completion/git-prompt.sh | 79 ++++++++++++++++++++++------------------\n>  1 file changed, 43 insertions(+), 36 deletions(-)\n>\n> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n> index fb9296b..263d2d7 100644\n> --- a/contrib/completion/git-prompt.sh\n> +++ b/contrib/completion/git-prompt.sh\n> @@ -222,6 +222,48 @@ __git_ps1_show_upstream ()\n>  \n>  }\n>  \n> +# Helper function that is meant to be called from __git_ps1.  It\n> +# builds up a gitstring injecting color codes into the appropriate\n> +# places.\n> +__git_ps1_colorize_gitstring ()\n> +{\n> +\tlocal c_red='\\e[31m'\n> +\tlocal c_green='\\e[32m'\n> +\tlocal c_lblue='\\e[1;34m'\n> +\tlocal c_clear='\\e[0m'\n> +\tlocal bad_color=$c_red\n> +\tlocal ok_color=$c_green\n> +\tlocal branch_color=\"$c_clear\"\n> +\tlocal flags_color=\"$c_lblue\"\n> +\tlocal branchstring=\"$c${b##refs/heads/}\"\n> +\n> +\tif [ $detached = no ]; then\n> +\t\tbranch_color=\"$ok_color\"\n> +\telse\n> +\t\tbranch_color=\"$bad_color\"\n> +\tfi\n> +\n> +\t# Setting gitstring directly with \\[ and \\] around colors\n> +\t# is necessary to prevent wrapping issues!\n> +\tgitstring=\"\\[$branch_color\\]$branchstring\\[$c_clear\\]\"\n> +\n> +\tif [ -n \"$w$i$s$u$r$p\" ]; then\n> +\t\tgitstring=\"$gitstring$z\"\n> +\tfi\n> +\tif [ \"$w\" = \"*\" ]; then\n> +\t\tgitstring=\"$gitstring\\[$bad_color\\]$w\"\n> +\tfi\n> +\tif [ -n \"$i\" ]; then\n> +\t\tgitstring=\"$gitstring\\[$ok_color\\]$i\"\n> +\tfi\n\nThis is somewhat offtopic, but does anybody remember why $w (and\nonly $w) has to be checked against '*', instead of [ -n \"$w\" ]?\n\nThe primary reason I ask is because from time to time I hear people\nwho forget what these *#$% line noises mean and have been wondering\nif we can add a GIT_PS1_SHOW_STATE_MNEMONIC option that shows these\nwith mnemonic letter sequences (e.g. \"wsu\" for dirty working tree,\nunmodified index, with stash and untracked files).\n\n> +\tif [ -n \"$s\" ]; then\n> +\t\tgitstring=\"$gitstring\\[$flags_color\\]$s\"\n> +\tfi\n> +\tif [ -n \"$u\" ]; then\n> +\t\tgitstring=\"$gitstring\\[$bad_color\\]$u\"\n> +\tfi\n> +\tgitstring=\"$gitstring\\[$c_clear\\]$r$p\"\n> +}\n>  \n>  # __git_ps1 accepts 0 or 1 arguments (i.e., format string)\n>  # when called from PS1 using command substitution\n> @@ -364,42 +406,7 @@ __git_ps1 ()\n>  \t\tif [ $pcmode = yes ]; then\n>  \t\t\tlocal gitstring=\n>  \t\t\tif [ -n \"${GIT_PS1_SHOWCOLORHINTS-}\" ]; then\n> -\t\t\t\tlocal c_red='\\e[31m'\n> -\t\t\t\tlocal c_green='\\e[32m'\n> -\t\t\t\tlocal c_lblue='\\e[1;34m'\n> -\t\t\t\tlocal c_clear='\\e[0m'\n> -\t\t\t\tlocal bad_color=$c_red\n> -\t\t\t\tlocal ok_color=$c_green\n> -\t\t\t\tlocal branch_color=\"$c_clear\"\n> -\t\t\t\tlocal flags_color=\"$c_lblue\"\n> -\t\t\t\tlocal branchstring=\"$c${b##refs/heads/}\"\n> -\n> -\t\t\t\tif [ $detached = no ]; then\n> -\t\t\t\t\tbranch_color=\"$ok_color\"\n> -\t\t\t\telse\n> -\t\t\t\t\tbranch_color=\"$bad_color\"\n> -\t\t\t\tfi\n> -\n> -\t\t\t\t# Setting gitstring directly with \\[ and \\] around colors\n> -\t\t\t\t# is necessary to prevent wrapping issues!\n> -\t\t\t\tgitstring=\"\\[$branch_color\\]$branchstring\\[$c_clear\\]\"\n> -\n> -\t\t\t\tif [ -n \"$w$i$s$u$r$p\" ]; then\n> -\t\t\t\t\tgitstring=\"$gitstring$z\"\n> -\t\t\t\tfi\n> -\t\t\t\tif [ \"$w\" = \"*\" ]; then\n> -\t\t\t\t\tgitstring=\"$gitstring\\[$bad_color\\]$w\"\n> -\t\t\t\tfi\n> -\t\t\t\tif [ -n \"$i\" ]; then\n> -\t\t\t\t\tgitstring=\"$gitstring\\[$ok_color\\]$i\"\n> -\t\t\t\tfi\n> -\t\t\t\tif [ -n \"$s\" ]; then\n> -\t\t\t\t\tgitstring=\"$gitstring\\[$flags_color\\]$s\"\n> -\t\t\t\tfi\n> -\t\t\t\tif [ -n \"$u\" ]; then\n> -\t\t\t\t\tgitstring=\"$gitstring\\[$bad_color\\]$u\"\n> -\t\t\t\tfi\n> -\t\t\t\tgitstring=\"$gitstring\\[$c_clear\\]$r$p\"\n> +\t\t\t\t__git_ps1_colorize_gitstring\n>  \t\t\telse\n>  \t\t\t\tgitstring=\"$c${b##refs/heads/}${f:+$z$f}$r$p\"\n>  \t\t\tfi\n"}]}