Thread (10 messages) flat view 10 messages, 4 authors, 2016-06-15

Re: [PATCH] Add __git_ps1_pc to use as PROMPT_COMMAND

From: Simon Oosthoek <hidden>
Date: 2016-06-15 22:54:58

Possibly related (same subject, not in this thread)

Hi Junio

I hope you found my patches, if not, I'll try to send them out again. 
(Unfortunately my current mail setup is a mess and I need time to figure 
out what to fix...)

As for the zsh support, I found out a little bit more.
ZSH doesn't have a variable like PROMPT_COMMAND in bash. The precmd name 
is a function the user has to define herself to have it called before 
the prompt is shown. Functionally this is almost, but not quite, the 
same as PROMPT_COMMAND. The subtle difference is that with 
PROMPT_COMMAND you can use parameters to customize the prompt, so in 
bash you can say:

PROMPT_COMMAND="__git_ps1 '\u@\[\e[1;34m\]\h\[\e[0m\]:\w' '\\\$ '"

where in zsh, if you want the status in the prompt, you can either use 
$(__git_ps1 "(%s)") or something like it in setting the PS1 (and forget 
about the color hints!) or you can copy the __git_ps1 function and 
modify and rename it as precmd to set PS1 via that function. Obviously 
it is probably even more complicated, but I'd have to try it to be certain.

An alternative way might be to set special variables from __git_set_vars 
function which may be used in a custom precmd to set the prompt.

e.g. say __git_set_vars sets __GIT_VAR_STATE=dirty|stage|clean

in precmd you could do
case $__GIT_VAR_STATE in
(dirty) PS1="$PS1 files modified in __GIT_VAR_BRANCHNAME"
;;
(stage) PS1="$PS1 files staged in __GIT_VAR_BRANCHNAME"
;;
(clean) PS1="$PS1 __GIT_VAR_BRANCHNAME clean"
;;
esac

(more or less of course)..

In that way it would be possible to add the colors relatively easily 
based on the state of the tree in a custom precmd function of zsh.

/Simon
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help