Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save intrueder/2ec30f75c8ef89914f24decc955ef67d to your computer and use it in GitHub Desktop.

Select an option

Save intrueder/2ec30f75c8ef89914f24decc955ef67d to your computer and use it in GitHub Desktop.

Revisions

  1. @reinvanoyen reinvanoyen revised this gist Dec 21, 2022. 1 changed file with 13 additions and 5 deletions.
    18 changes: 13 additions & 5 deletions terminal-prompt-git-branch-zsh.md
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,28 @@
    # Add Git Branch Name to Terminal Prompt (MacOS Catalina zsh)
    ## Updated for MacOS Big Sur | Monterey | Ventura

    <img width="822" alt="screenshot" src="https://user-images.githubusercontent.com/513140/71285442-13d6db00-235d-11ea-8ba6-5bfe45739888.png">

    ### Install
    Open `~/.zshrc` in your favorite editor and add the following content to the bottom.

    ```sh
    function parse_git_branch() {
    git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
    }

    COLOR_DEF=$'\e[0m'
    COLOR_USR=$'\e[38;5;243m'
    COLOR_DIR=$'\e[38;5;197m'
    COLOR_GIT=$'\e[38;5;39m'
    COLOR_DEF=$'%f'
    COLOR_USR=$'%F{243}'
    COLOR_DIR=$'%F{197}'
    COLOR_GIT=$'%F{39}'
    setopt PROMPT_SUBST
    export PROMPT='${COLOR_USR}%n ${COLOR_DIR}%~ ${COLOR_GIT}$(parse_git_branch)${COLOR_DEF} $ '
    ```

    Original gist for Bash by Jose Quintana: https://gist.github.com/joseluisq/1e96c54fa4e1e5647940
    ### Reload and apply adjustments
    To reload and apply adjustments to the formatting use `source ~/.zshrc` in the zsh shell.

    ### Credits
    * Thank you benP2ER for the useful additions in [his comment](https://gist.github.com/reinvanoyen/05bcfe95ca9cb5041a4eafd29309ff29?permalink_comment_id=4117181#gistcomment-4117181)
    * Original gist by Jose Quintana: [Add Git Branch Name to Terminal Prompt (Linux/Mac)
    ](https://gist.github.com/joseluisq/1e96c54fa4e1e5647940)
  2. @reinvanoyen reinvanoyen revised this gist Dec 20, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion terminal-prompt-git-branch-zsh.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,8 @@
    # Add Git Branch Name to Terminal Prompt (MacOS Catalina zsh)

    <img width="822" alt="screenshot" src="https://user-images.githubusercontent.com/513140/71285442-13d6db00-235d-11ea-8ba6-5bfe45739888.png">
    Open ~/.zshrc in your favorite editor and add the following content to the bottom.

    Open `~/.zshrc` in your favorite editor and add the following content to the bottom.

    ```sh
    function parse_git_branch() {
  3. @reinvanoyen reinvanoyen revised this gist Dec 20, 2019. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions terminal-prompt-git-branch-zsh.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    # Add Git Branch Name to Terminal Prompt (MacOS Catalina zsh)

    ![image](https://cloud.githubusercontent.com/assets/1700322/8341607/93e820d6-1a8b-11e5-81c8-3dd429270068.png)

    <img width="822" alt="screenshot" src="https://user-images.githubusercontent.com/513140/71285442-13d6db00-235d-11ea-8ba6-5bfe45739888.png">
    Open ~/.zshrc in your favorite editor and add the following content to the bottom.

    ```sh
  4. @reinvanoyen reinvanoyen revised this gist Dec 20, 2019. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion terminal-prompt-git-branch-zsh.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@
    # Add Git Branch Name to Terminal Prompt (MacOS Catalina zsh)

    ![image](https://cloud.githubusercontent.com/assets/1700322/8341607/93e820d6-1a8b-11e5-81c8-3dd429270068.png)

    Open ~/.zshrc in your favorite editor and add the following content to the bottom.

    ```sh
    @@ -11,4 +15,6 @@ COLOR_DIR=$'\e[38;5;197m'
    COLOR_GIT=$'\e[38;5;39m'
    setopt PROMPT_SUBST
    export PROMPT='${COLOR_USR}%n ${COLOR_DIR}%~ ${COLOR_GIT}$(parse_git_branch)${COLOR_DEF} $ '
    ```
    ```

    Original gist for Bash by Jose Quintana: https://gist.github.com/joseluisq/1e96c54fa4e1e5647940
  5. @reinvanoyen reinvanoyen revised this gist Dec 20, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion terminal-prompt-git-branch-zsh.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    Open ~/.zshrc in your favorite editor and add the following content to the bottom.

    ```ssh
    ```sh
    function parse_git_branch() {
    git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
    }
  6. @reinvanoyen reinvanoyen created this gist Dec 20, 2019.
    14 changes: 14 additions & 0 deletions terminal-prompt-git-branch-zsh.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    Open ~/.zshrc in your favorite editor and add the following content to the bottom.

    ```ssh
    function parse_git_branch() {
    git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
    }
    COLOR_DEF=$'\e[0m'
    COLOR_USR=$'\e[38;5;243m'
    COLOR_DIR=$'\e[38;5;197m'
    COLOR_GIT=$'\e[38;5;39m'
    setopt PROMPT_SUBST
    export PROMPT='${COLOR_USR}%n ${COLOR_DIR}%~ ${COLOR_GIT}$(parse_git_branch)${COLOR_DEF} $ '
    ```