Search code examples
bashgithubosx-mountain-lioncommand-prompt

Is there any way to display github user name in prompt


Sometimes I have to work with multiple Github accounts. Different email and name. And what happens all the time is I accidentally commit with wrong user and everything this messes up everything (scenario is both the users have access to that repo but one user is wrong). So to avoid this I want to display github user email in prompt.

export PS1=$(git config user.email)

Above bashrc entry works but it doesn't update itself when I cd to a Github repo with different github email and username setup.

I am on mac.


Solution

  • Rather, set it as

    PROMPT_COMMAND='PS1=$(git config user.email)'
    

    Example

    PROMPT_COMMAND
        If set, the value is executed as a command prior to issuing each primary 
        prompt. 
    

    bash(1)