Problem
I have oh my zsh installed on mac OS catalina and using iTerm2 as terminal. I am using robbyrussell.zsh-theme theme and have modified it to print git email in the prompt (More info here). I have modified robbyrussell.zsh-theme to this:
PROMPT="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
PROMPT+=' %{$fg[cyan]%}%~%{$reset_color%} $(git_prompt_info)'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[blue]%}$(git_current_user_email)["
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}] %{$fg[yellow]%}✗"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%}] %{$fg[green]%}✔"
When I move to a git directory it is not picking up user email from local .git/config or from global ~/.git/config.
Research done:
I went through multiple stackoverflow and other articles and tried bunch of stuff but with no success.
The approach that worked for me was creating aliases to switch between two email addresses:
home='git config user.email "<homeemail>" && source ~/.zshrc'
work='git config user.email "<workemail>" && source ~/.zshrc'
But I have to execute these commands all the time to make prompt pick up the email even if it is set in local git config.
Can someone help regarding what needs to be done to zsh prompt to read git user email directly when we cd to a repo?