{"thread":{"id":"33808","subject":"[PATCH v2 0/3] Colored prompt for ZSH","startedAt":"2013-05-13T13:49:15Z","lastAt":"2013-05-16T12:12:08Z","messageCount":6,"participants":["Ramkumar Ramachandra","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":3},"messages":[{"id":"217165","messageId":"1368452958-31090-1-git-send-email-artagnon@gmail.com","threadId":"33808","inReplyTo":null,"subject":"[PATCH v2 0/3] Colored prompt for ZSH","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-05-13T13:49:15Z","receivedAt":"2013-05-13T13:49:15Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Thanks to Felipe, SZEDER, and Junio for a review of v1.  This is a v2\nin response to those reviews.\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 | 128 +++++++++++++++++++++++++++------------\n 1 file changed, 89 insertions(+), 39 deletions(-)\n\n-- \n1.8.3.rc1.57.g4ac1522\n"},{"id":"217166","messageId":"1368452958-31090-2-git-send-email-artagnon@gmail.com","threadId":"33808","inReplyTo":"1368452958-31090-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-13T13:49:16Z","receivedAt":"2013-05-13T13:49:16Z","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 | 11 ++++++++---\n 1 file changed, 8 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex eaf5c36..5d8b745 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -359,6 +359,11 @@ __git_ps1 ()\n \t\t\tfi\n \t\tfi\n \n+\t\tlocal z=\" \"\n+\t\tif [ -n \"${GIT_PS1_STATESEPARATOR+set}\" ]; then\n+\t\t\tz=\"${GIT_PS1_STATESEPARATOR}\"\n+\t\tfi\n+\n \t\tlocal f=\"$w$i$s$u\"\n \t\tif [ $pcmode = yes ]; then\n \t\t\tlocal gitstring=\n@@ -384,7 +389,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 +405,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.3.rc1.57.g4ac1522\n"},{"id":"217167","messageId":"1368452958-31090-3-git-send-email-artagnon@gmail.com","threadId":"33808","inReplyTo":"1368452958-31090-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-13T13:49:17Z","receivedAt":"2013-05-13T13:49:17Z","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 5d8b745..6943f86 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@@ -368,42 +410,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.3.rc1.57.g4ac1522\n"},{"id":"217168","messageId":"1368452958-31090-4-git-send-email-artagnon@gmail.com","threadId":"33808","inReplyTo":"1368452958-31090-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-13T13:49:18Z","receivedAt":"2013-05-13T13:49:18Z","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 6943f86..e2dd8a8 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.3.rc1.57.g4ac1522\n"},{"id":"217197","messageId":"7vli7ioqzx.fsf@alter.siamese.dyndns.org","threadId":"33808","inReplyTo":"1368452958-31090-2-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 1/3] prompt: introduce GIT_PS1_STATESEPARATOR","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-05-13T15:10:10Z","receivedAt":"2013-05-13T15:10:10Z","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> A typical prompt looks like:\n>\n>     artagnon|master *=:~/src/git$\n>                    ^\n>                    why do we have this space?\n>\n> Nobody has branch names that end with +, *, =, < or > anyway, so it\n> doesn't serve the purpose of disambiguation.\n>\n> Make this separator configurable via GIT_PS1_STATESEPARATOR.  This means\n> that you can set it to \"\" and get this prompt:\n>\n>     artagnon|master*=:~/src/git$\n>\n> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n> ---\n>  contrib/completion/git-prompt.sh | 11 ++++++++---\n>  1 file changed, 8 insertions(+), 3 deletions(-)\n>\n> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n> index eaf5c36..5d8b745 100644\n> --- a/contrib/completion/git-prompt.sh\n> +++ b/contrib/completion/git-prompt.sh\n> @@ -359,6 +359,11 @@ __git_ps1 ()\n>  \t\t\tfi\n>  \t\tfi\n>  \n> +\t\tlocal z=\" \"\n> +\t\tif [ -n \"${GIT_PS1_STATESEPARATOR+set}\" ]; then\n> +\t\t\tz=\"${GIT_PS1_STATESEPARATOR}\"\n> +\t\tfi\n\nIt is simpler to use 'default values', no?\n\n\tlocal z=${GIT_PS1_STATESEPARATOR-\" \"}\n\n> @@ -384,7 +389,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\nPerhaps not even a nit, but you do not have to concatenate when $z\nis set to empty, so it may be worth doing\n\n    if [ -n \"$w$i$s$u$r$p\" ] && [ -n \"$z\" ]; then\n\tgitstring=\"$gitstring$z\"\n    fi\n"},{"id":"217584","messageId":"CALkWK0m7=A0rRj3NzMorGjgSqbfqQow+etbH0v0wrtSRW33tnQ@mail.gmail.com","threadId":"33808","inReplyTo":"7vli7ioqzx.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 1/3] prompt: introduce GIT_PS1_STATESEPARATOR","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-05-16T12:12:08Z","receivedAt":"2013-05-16T12:12:08Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Junio C Hamano wrote:\n> It is simpler to use 'default values', no?\n>\n>         local z=${GIT_PS1_STATESEPARATOR-\" \"}\n\nThere don't seem to be any more comments.  If there are no issues,\ncould you fix this up locally before queueing?\n\nThanks.\n"}]}