{"thread":{"id":"33797","subject":"[PATCH 0/2] Colored prompt for zsh","startedAt":"2013-05-11T16:25:11Z","lastAt":"2013-05-13T14:21:50Z","messageCount":16,"participants":["Ramkumar Ramachandra","Felipe Contreras","Junio C Hamano","SZEDER Gábor"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"217024","messageId":"1368289513-8700-1-git-send-email-artagnon@gmail.com","threadId":"33797","inReplyTo":null,"subject":"[PATCH 0/2] Colored prompt for zsh","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-05-11T16:25:11Z","receivedAt":"2013-05-11T16:25:11Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nI was using ZSH's vcs_info until now, and just discovered\ncontrib/completion/git-prompt.sh.  Other differences aside, it's\nsimple enough that I can hack on it.\n\nThe first patch strips a small whitespace (we can't waste valuable\nreal estate on unnecessary whitespace), and the second patch should\nget you a beautiful colored prompt in ZSH.\n\nEnjoy!\n\nRamkumar Ramachandra (2):\n  git-prompt.sh: strip unnecessary space in prompt string\n  git-prompt.zsh: introduce thin ZSH wrapper\n\n contrib/completion/git-prompt.sh  | 80 ++++++++++++++++++++-------------------\n contrib/completion/git-prompt.zsh | 59 +++++++++++++++++++++++++++++\n 2 files changed, 101 insertions(+), 38 deletions(-)\n create mode 100644 contrib/completion/git-prompt.zsh\n\n-- \n1.8.3.rc1.52.g4537cf1\n"},{"id":"217025","messageId":"1368289513-8700-2-git-send-email-artagnon@gmail.com","threadId":"33797","inReplyTo":"1368289513-8700-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-05-11T16:25:12Z","receivedAt":"2013-05-11T16:25:12Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Nobody has branch names that end with + or *.  Then why put a space\nafter the branch name and before [*|+][=|<|>] in the prompt string?\n\nBefore this, your prompt might have looked like:\n\n    artagnon|master *=:~/src/git$\n\nNow, it will look like:\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, 2 insertions(+), 5 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex eaf5c36..08c9b22 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -383,9 +383,6 @@ __git_ps1 ()\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 \"\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@@ -400,13 +397,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:+$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:+$f}$r$p\"\n \t\tfi\n \tfi\n }\n-- \n1.8.3.rc1.52.g4537cf1\n"},{"id":"217026","messageId":"1368289513-8700-3-git-send-email-artagnon@gmail.com","threadId":"33797","inReplyTo":"1368289513-8700-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 2/2] git-prompt.zsh: introduce thin ZSH wrapper","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-05-11T16:25:13Z","receivedAt":"2013-05-11T16:25:13Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"To facilitate a colored prompt in ZSH, write a thin wrapper around\ngit-prompt.sh, factoring out and overriding the coloring logic.  Since\nZSH lacks a PROMPT_COMMAND, instruct the user to execute __git_ps1\ninside precmd().\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n contrib/completion/git-prompt.sh  | 73 +++++++++++++++++++++------------------\n contrib/completion/git-prompt.zsh | 59 +++++++++++++++++++++++++++++++\n 2 files changed, 99 insertions(+), 33 deletions(-)\n create mode 100644 contrib/completion/git-prompt.zsh\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 08c9b22..0bc51ad 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -222,6 +222,45 @@ __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 [ \"$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@@ -363,39 +402,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 [ \"$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:+$f}$r$p\"\n \t\t\tfi\ndiff --git a/contrib/completion/git-prompt.zsh b/contrib/completion/git-prompt.zsh\nnew file mode 100644\nindex 0000000..dc164dd\n--- /dev/null\n+++ b/contrib/completion/git-prompt.zsh\n@@ -0,0 +1,59 @@\n+# git prompt support for zsh: wrapper around git-prompt.sh\n+#\n+# To enable:\n+#\n+#    1) Copy this file and git-prompt.sh to ~/.zsh/prompt\n+#    2) Add the following lines to your .zshrc:\n+#\n+#          source ~/.zsh/prompt/git-prompt.zsh\n+#          GIT_PS1_SHOWCOLORHINTS=true\n+#          precmd () { __git_ps1 \"%n|\" \":%~$ \" \"%s\" }\n+#\n+#    3) You can now add the following to ~/.zshrc and expect the\n+#       characters to be displayed in color:\n+#\n+#          GIT_PS1_DESCRIBE_STYLE=branch\n+#          GIT_PS1_SHOWUPSTREAM=auto\n+#          GIT_PS1_SHOWDIRTYSTATE=true\n+#          GIT_PS1_SHOWUNTRACKEDFILES=true\n+\n+test -z \"$script\" && script=\"$(dirname ${funcsourcetrace[1]%:*})\"/git-prompt.sh\n+ZSH_VERSION='' . \"$script\"\n+\n+autoload colors\n+colors\n+\n+__git_ps1_colorize_gitstring ()\n+{\n+\tlocal c_red='%F{red}'\n+\tlocal c_green='%F{green}'\n+\tlocal c_lblue='%F{blue}'\n+\tlocal c_clear='%f'\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+\tgitstring=\"$branch_color$branchstring$c_clear\"\n+\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-- \n1.8.3.rc1.52.g4537cf1\n"},{"id":"217045","messageId":"CAMP44s1pO+ytNWEV6ykRn671yf50+oMZQMnrcTN+s5ykPRpumg@mail.gmail.com","threadId":"33797","inReplyTo":"1368289513-8700-3-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 2/2] git-prompt.zsh: introduce thin ZSH wrapper","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-05-11T21:26:52Z","receivedAt":"2013-05-11T21:26:52Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sat, May 11, 2013 at 11:25 AM, Ramkumar Ramachandra\n<artagnon@gmail.com> wrote:\n> To facilitate a colored prompt in ZSH, write a thin wrapper around\n> git-prompt.sh, factoring out and overriding the coloring logic.  Since\n> ZSH lacks a PROMPT_COMMAND, instruct the user to execute __git_ps1\n> inside precmd().\n\nI think this is two logical changes into one.\n\n> --- /dev/null\n> +++ b/contrib/completion/git-prompt.zsh\n> @@ -0,0 +1,59 @@\n> +# git prompt support for zsh: wrapper around git-prompt.sh\n> +#\n> +# To enable:\n> +#\n> +#    1) Copy this file and git-prompt.sh to ~/.zsh/prompt\n> +#    2) Add the following lines to your .zshrc:\n> +#\n> +#          source ~/.zsh/prompt/git-prompt.zsh\n> +#          GIT_PS1_SHOWCOLORHINTS=true\n> +#          precmd () { __git_ps1 \"%n|\" \":%~$ \" \"%s\" }\n> +#\n> +#    3) You can now add the following to ~/.zshrc and expect the\n> +#       characters to be displayed in color:\n> +#\n> +#          GIT_PS1_DESCRIBE_STYLE=branch\n> +#          GIT_PS1_SHOWUPSTREAM=auto\n> +#          GIT_PS1_SHOWDIRTYSTATE=true\n> +#          GIT_PS1_SHOWUNTRACKEDFILES=true\n> +\n> +test -z \"$script\" && script=\"$(dirname ${funcsourcetrace[1]%:*})\"/git-prompt.sh\n> +ZSH_VERSION='' . \"$script\"\n\nI've been thinking that this method of loading the script is not the\nbest; we should probably have a list of locations where distributions\nusually put this file. So if we could avoid the creation of of a new\nfile, that would be great.\n\n> +autoload colors\n> +colors\n> +\n> +__git_ps1_colorize_gitstring ()\n> +{\n> +       local c_red='%F{red}'\n> +       local c_green='%F{green}'\n> +       local c_lblue='%F{blue}'\n> +       local c_clear='%f'\n> +       local bad_color=$c_red\n> +       local ok_color=$c_green\n> +       local branch_color=\"$c_clear\"\n> +       local flags_color=\"$c_lblue\"\n> +       local branchstring=\"$c${b##refs/heads/}\"\n\nThis is the only real difference with bash colors, no? I think it's\noverkill to create a new file, and load the old one, only to override\npart of a function. We should probably start with everything in the\nsame file, and only later if we find it's necessary, split.\n\n> +       if [ $detached = no ]; then\n> +               branch_color=\"$ok_color\"\n> +       else\n> +               branch_color=\"$bad_color\"\n> +       fi\n> +\n> +       gitstring=\"$branch_color$branchstring$c_clear\"\n> +\n> +       if [ \"$w\" = \"*\" ]; then\n> +               gitstring=\"$gitstring$bad_color$w\"\n> +       fi\n> +       if [ -n \"$i\" ]; then\n> +               gitstring=\"$gitstring$ok_color$i\"\n> +       fi\n> +       if [ -n \"$s\" ]; then\n> +               gitstring=\"$gitstring$flags_color$s\"\n> +       fi\n> +       if [ -n \"$u\" ]; then\n> +               gitstring=\"$gitstring$bad_color$u\"\n> +       fi\n> +       gitstring=\"$gitstring$c_clear$r$p\"\n> +}\n> --\n\n-- \nFelipe Contreras\n"},{"id":"217047","messageId":"1368310739-24099-1-git-send-email-artagnon@gmail.com","threadId":"33797","inReplyTo":"CAMP44s1pO+ytNWEV6ykRn671yf50+oMZQMnrcTN+s5ykPRpumg@mail.gmail.com","subject":"[PATCH v2] git-prompt.sh: colorize ZSH prompt","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-05-11T22:18:59Z","receivedAt":"2013-05-11T22:18:59Z","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 You like this more?  I don't mind going either way.\n\n contrib/completion/git-prompt.sh | 67 ++++++++++++++++++++++++++++------------\n 1 file changed, 47 insertions(+), 20 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 08c9b22..26e5bc2 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@@ -363,10 +364,18 @@ __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\tif [[ -n ${ZSH_VERSION-} ]]; then\n+\t\t\t\t\tlocal c_red='%F{red}'\n+\t\t\t\t\tlocal c_green='%F{green}'\n+\t\t\t\t\tlocal c_lblue='%F{blue}'\n+\t\t\t\t\tlocal c_clear='%f'\n+\t\t\t\telse\n+\t\t\t\t\tlocal c_red='\\e[31m'\n+\t\t\t\t\tlocal c_green='\\e[32m'\n+\t\t\t\t\tlocal c_lblue='\\e[1;34m'\n+\t\t\t\t\tlocal c_clear='\\e[0m'\n+\t\t\t\tfi\n+\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@@ -379,23 +388,41 @@ __git_ps1 ()\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+\t\t\t\tif [[ -n ${ZSH_VERSION-} ]]; then\n+\t\t\t\t\tgitstring=\"$branch_color$branchstring$c_clear\"\n \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\t\tif [ \"$w\" = \"*\" ]; then\n+\t\t\t\t\t\tgitstring=\"$gitstring$bad_color$w\"\n+\t\t\t\t\tfi\n+\t\t\t\t\tif [ -n \"$i\" ]; then\n+\t\t\t\t\t\tgitstring=\"$gitstring$ok_color$i\"\n+\t\t\t\t\tfi\n+\t\t\t\t\tif [ -n \"$s\" ]; then\n+\t\t\t\t\t\tgitstring=\"$gitstring$flags_color$s\"\n+\t\t\t\t\tfi\n+\t\t\t\t\tif [ -n \"$u\" ]; then\n+\t\t\t\t\t\tgitstring=\"$gitstring$bad_color$u\"\n+\t\t\t\t\tfi\n+\t\t\t\t\tgitstring=\"$gitstring$c_clear$r$p\"\n+\t\t\t\telse\n+\t\t\t\t\t# Setting gitstring directly with \\[ and \\] around colors\n+\t\t\t\t\t# is necessary to prevent wrapping issues!\n+\t\t\t\t\tgitstring=\"\\[$branch_color\\]$branchstring\\[$c_clear\\]\"\n+\n+\t\t\t\t\tif [ \"$w\" = \"*\" ]; then\n+\t\t\t\t\t\tgitstring=\"$gitstring\\[$bad_color\\]$w\"\n+\t\t\t\t\tfi\n+\t\t\t\t\tif [ -n \"$i\" ]; then\n+\t\t\t\t\t\tgitstring=\"$gitstring\\[$ok_color\\]$i\"\n+\t\t\t\t\tfi\n+\t\t\t\t\tif [ -n \"$s\" ]; then\n+\t\t\t\t\t\tgitstring=\"$gitstring\\[$flags_color\\]$s\"\n+\t\t\t\t\tfi\n+\t\t\t\t\tif [ -n \"$u\" ]; then\n+\t\t\t\t\t\tgitstring=\"$gitstring\\[$bad_color\\]$u\"\n+\t\t\t\t\tfi\n+\t\t\t\t\tgitstring=\"$gitstring\\[$c_clear\\]$r$p\"\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\tfi\n-- \n1.8.3.rc1.46.gfc3cab0\n"},{"id":"217048","messageId":"CAMP44s1B+FfdKebpTq+AwHP3YCiiVc++rtc8wqOn8EOy1dyLwA@mail.gmail.com","threadId":"33797","inReplyTo":"1368310739-24099-1-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH v2] git-prompt.sh: colorize ZSH prompt","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-05-11T22:29:52Z","receivedAt":"2013-05-11T22:29:52Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sat, May 11, 2013 at 5:18 PM, Ramkumar Ramachandra\n<artagnon@gmail.com> wrote:\n> Add colors suitable for use in the ZSH prompt.  Having learnt that the\n> ZSH equivalent of PROMPT_COMMAND is precmd (), you can now use\n> GIT_PS1_SHOWCOLORHINTS with ZSH.\n>\n> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n> ---\n>  You like this more?  I don't mind going either way.\n\nNot really. If we need to avoid the \\[\\], it makes sense to have a\nseparate function, but what I meant is that this function should be\ninitially on the same file, and created in a separate patch.\n\n-- \nFelipe Contreras\n"},{"id":"217049","messageId":"CALkWK0mySjW_QGObkXWvhzMa0gbwKDire4Dx9=PV+9OnEgZjsQ@mail.gmail.com","threadId":"33797","inReplyTo":"CAMP44s1B+FfdKebpTq+AwHP3YCiiVc++rtc8wqOn8EOy1dyLwA@mail.gmail.com","subject":"Re: [PATCH v2] git-prompt.sh: colorize ZSH prompt","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-05-11T22:40:13Z","receivedAt":"2013-05-11T22:40:13Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Felipe Contreras wrote:\n> Not really. If we need to avoid the \\[\\], it makes sense to have a\n> separate function, but what I meant is that this function should be\n> initially on the same file, and created in a separate patch.\n\nWhat are you saying?\n\n1. It makes sense to have a separate function specifically for ZSH,\nbut it should be located in the same physical file (why?)\n2. You like the original patch, but would prefer two different parts (a nit)\n"},{"id":"217051","messageId":"CAMP44s0QKGVzWohsbyN_7EdW1WxHvqDrjpuCykxNFkUKi=XKbA@mail.gmail.com","threadId":"33797","inReplyTo":"CALkWK0mySjW_QGObkXWvhzMa0gbwKDire4Dx9=PV+9OnEgZjsQ@mail.gmail.com","subject":"Re: [PATCH v2] git-prompt.sh: colorize ZSH prompt","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-05-11T23:06:48Z","receivedAt":"2013-05-11T23:06:48Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sat, May 11, 2013 at 5:40 PM, Ramkumar Ramachandra\n<artagnon@gmail.com> wrote:\n> Felipe Contreras wrote:\n>> Not really. If we need to avoid the \\[\\], it makes sense to have a\n>> separate function, but what I meant is that this function should be\n>> initially on the same file, and created in a separate patch.\n>\n> What are you saying?\n>\n> 1. It makes sense to have a separate function specifically for ZSH,\n> but it should be located in the same physical file (why?)\n\nThis is what I mean:\n\ncommit 4726a5f76ec7d96c34863d6640488e2183cc8f00\nAuthor: Ramkumar Ramachandra <artagnon@gmail.com>\nDate:   Sat May 11 21:55:13 2013 +0530\n\n    prompt: split code into __git_ps1_colorize_gitstring()\n\n    Will be useful for reorganizations.\n\n    Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex eaf5c36..1187292 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -222,6 +222,45 @@ __git_ps1_show_upstream ()\n\n }\n\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 \"\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@@ -363,42 +402,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 \"\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:+ $f}$r$p\"\n \t\t\tfi\n\ncommit 23d89b370ac36401da1d9a98754e222a7a4c93e5\nAuthor: Felipe Contreras <felipe.contreras@gmail.com>\nDate:   Sat May 11 18:03:39 2013 -0500\n\n    prompt: add colorization for zsh\n\n    Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 1187292..8946a29 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -224,6 +224,8 @@ __git_ps1_show_upstream ()\n\n __git_ps1_colorize_gitstring ()\n {\n+\tif [[ -z ${ZSH_VERSION-} ]]\n+\tthen\n \t\tlocal c_red='\\e[31m'\n \t\tlocal c_green='\\e[32m'\n \t\tlocal c_lblue='\\e[1;34m'\n@@ -260,6 +262,39 @@ __git_ps1_colorize_gitstring ()\n \t\t\tgitstring=\"$gitstring\\[$bad_color\\]$u\"\n \t\tfi\n \t\tgitstring=\"$gitstring\\[$c_clear\\]$r$p\"\n+\telse\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 [ \"$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+\tfi\n }\n\n # __git_ps1 accepts 0 or 1 arguments (i.e., format string)\n\n-- \nFelipe Contreras\n"},{"id":"217115","messageId":"7v61ynsci8.fsf@alter.siamese.dyndns.org","threadId":"33797","inReplyTo":"1368289513-8700-2-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-05-13T04:57:19Z","receivedAt":"2013-05-13T04:57:19Z","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> Nobody has branch names that end with + or *.  Then why put a space\n> after the branch name and before [*|+][=|<|>] in the prompt string?\n\nI do not think the space is for disambiguation.\n\nIt is like asking why typeset a space after a sentence a tad wider\nthan a space after each word: grouping related things together, and\nseparating groups of different kind apart, to make it more readable.\n"},{"id":"217131","messageId":"CALkWK0m0dT-sX=nu5jaDj=y1oOSo0cRKQ=2K_S-yepnsm8ny7A@mail.gmail.com","threadId":"33797","inReplyTo":"7v61ynsci8.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-05-13T07:40:26Z","receivedAt":"2013-05-13T07:40:26Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Junio C Hamano wrote:\n> It is like asking why typeset a space after a sentence a tad wider\n> than a space after each word:\n\nNot at all.  The prompt has nothing to do with sentences.\n\n> grouping related things together, and\n> separating groups of different kind apart, to make it more readable.\n\nYou could argue that the colors are not very well thought-out\n(branch-name has the same color as +), but I really don't see the\nproblem otherwise.  How is this more readable:\n\n    artagnon|master *=:~/src/git$\n\nthan:\n\n    artagnon|master*=:~/src/git$\n\n(where master is green, * is red, and = is white)?\n\nLooking at what we've done so far, I would argue that we're not\nthinking about the usability of the prompt enough: it currently\nscreams I AM DOING REBASE-i! (and similarly for other operations in\nprogress).  I intend to fix these things in future patches.\n\nThanks.\n"},{"id":"217146","messageId":"20130513091718.GA21636@goldbirke","threadId":"33797","inReplyTo":"CALkWK0m0dT-sX=nu5jaDj=y1oOSo0cRKQ=2K_S-yepnsm8ny7A@mail.gmail.com","subject":"Re: [PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2013-05-13T09:17:19Z","receivedAt":"2013-05-13T09:17:19Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Mon, May 13, 2013 at 01:10:26PM +0530, Ramkumar Ramachandra wrote:\n> Junio C Hamano wrote:\n> > grouping related things together, and\n> > separating groups of different kind apart, to make it more readable.\n> \n> You could argue that the colors are not very well thought-out\n> (branch-name has the same color as +), but I really don't see the\n> problem otherwise.  How is this more readable:\n> \n>     artagnon|master *=:~/src/git$\n> \n> than:\n> \n>     artagnon|master*=:~/src/git$\n> \n> (where master is green, * is red, and = is white)?\n\nIMHO that's just ugly ;)\n\nDon't forget that others might use a different prompt format and using\ncolors in the prompt is optional.  With the default prompt format and\nwithout colors I find that that space definitely helps readability.\n\n\nGábor\n"},{"id":"217147","messageId":"CALkWK0m+mG39W7RqU-9KfPWLnaey5pL+jvfdZg49ixsASE+QoQ@mail.gmail.com","threadId":"33797","inReplyTo":"20130513091718.GA21636@goldbirke","subject":"Re: [PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-05-13T10:13:43Z","receivedAt":"2013-05-13T10:13:43Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"SZEDER Gábor wrote:\n> Don't forget that others might use a different prompt format and using\n> colors in the prompt is optional.  With the default prompt format and\n> without colors I find that that space definitely helps readability.\n\nI'm finding it hard to believe that anyone would want to use a colorless prompt.\n\n> IMHO that's just ugly ;)\n\nIf we can agree that it's just a matter of taste, we should both be\nable to have what we want.  Any suggestions on how to make this\nconfigurable?\n"},{"id":"217148","messageId":"20130513110551.GT2331@goldbirke","threadId":"33797","inReplyTo":"CALkWK0m+mG39W7RqU-9KfPWLnaey5pL+jvfdZg49ixsASE+QoQ@mail.gmail.com","subject":"Re: [PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2013-05-13T11:05:51Z","receivedAt":"2013-05-13T11:05:51Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Mon, May 13, 2013 at 03:43:43PM +0530, Ramkumar Ramachandra wrote:\n> SZEDER Gábor wrote:\n> > Don't forget that others might use a different prompt format and using\n> > colors in the prompt is optional.  With the default prompt format and\n> > without colors I find that that space definitely helps readability.\n> \n> I'm finding it hard to believe that anyone would want to use a colorless prompt.\n\nWell, back then I was shell-shocked to find that there are people who\nwant colors in their prompt ;)\n\n> > IMHO that's just ugly ;)\n> \n> If we can agree that it's just a matter of taste, we should both be\n> able to have what we want.  Any suggestions on how to make this\n> configurable?\n\nThe same way we make other things configurable in the prompt: specify\nthe GIT_PS1_HIDESTATESEPARATOR or something similar variable to strip\nthat space from the prompt.\n"},{"id":"217149","messageId":"20130513111143.GU2331@goldbirke","threadId":"33797","inReplyTo":"20130513110551.GT2331@goldbirke","subject":"Re: [PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2013-05-13T11:11:43Z","receivedAt":"2013-05-13T11:11:43Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Mon, May 13, 2013 at 01:05:51PM +0200, SZEDER Gábor wrote:\n> On Mon, May 13, 2013 at 03:43:43PM +0530, Ramkumar Ramachandra wrote:\n> > If we can agree that it's just a matter of taste, we should both be\n> > able to have what we want.  Any suggestions on how to make this\n> > configurable?\n> \n> The same way we make other things configurable in the prompt: specify\n> the GIT_PS1_HIDESTATESEPARATOR or something similar variable to strip\n> that space from the prompt.\n\nOr perhaps better yet: use a variable, e.g. GIT_PS1_STATESEPARATOR or\nwhatever, to specify what should separate the branch name from the\nrepo state, defaulting to a space to keep the current behavior.\n\n\nGábor\n"},{"id":"217173","messageId":"7vvc6noubf.fsf@alter.siamese.dyndns.org","threadId":"33797","inReplyTo":"20130513111143.GU2331@goldbirke","subject":"Re: [PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-05-13T13:58:28Z","receivedAt":"2013-05-13T13:58:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"SZEDER Gábor <szeder@ira.uka.de> writes:\n\n> On Mon, May 13, 2013 at 01:05:51PM +0200, SZEDER Gábor wrote:\n>> On Mon, May 13, 2013 at 03:43:43PM +0530, Ramkumar Ramachandra wrote:\n>> > If we can agree that it's just a matter of taste, we should both be\n>> > able to have what we want.  Any suggestions on how to make this\n>> > configurable?\n>> \n>> The same way we make other things configurable in the prompt: specify\n>> the GIT_PS1_HIDESTATESEPARATOR or something similar variable to strip\n>> that space from the prompt.\n>\n> Or perhaps better yet: use a variable, e.g. GIT_PS1_STATESEPARATOR or\n> whatever, to specify what should separate the branch name from the\n> repo state, defaulting to a space to keep the current behavior.\n\nWhy just a single knob for that SP?  \n\nIf you restructure the code to formulate \"gitstring\" to call a shell\nfunction to do so, people can override it and come up with whatever\nformat they want to use, no?\n"},{"id":"217180","messageId":"CALkWK0=zqG6cyeZhK65nVQZunQinf=Ub=BPTJHx+ZWgAs2thag@mail.gmail.com","threadId":"33797","inReplyTo":"7vvc6noubf.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-05-13T14:21:50Z","receivedAt":"2013-05-13T14:21:50Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Junio C Hamano wrote:\n> If you restructure the code to formulate \"gitstring\" to call a shell\n> function to do so, people can override it and come up with whatever\n> format they want to use, no?\n\nThe user would essentially have to implement her own\n__git_ps1_colorize_string; a function that takes a lot of arguments\nand stitches them together with color.  Much too painful for little\ngain.\n"}]}