Skip to content

Instantly share code, notes, and snippets.

@kstromeiraos
Last active January 11, 2018 22:21
Show Gist options
  • Save kstromeiraos/df603fef5be1d80b5112046e0a720df4 to your computer and use it in GitHub Desktop.
Save kstromeiraos/df603fef5be1d80b5112046e0a720df4 to your computer and use it in GitHub Desktop.
Prompt with git branch and last command exit code (smiley)

Prompt with git branch and last command exit code (smiley)

screen shot 2018-01-11 at 23 18 59

Add this to the bottom of ~/.bash_profile file.

# Prompt
parse_git_branch() {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}

PROMPT_COMMAND=__prompt_command

__prompt_command() {
    local EXIT="$?"

    PS1="\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\[\033[0;36m\]@\[\033[0;36m\]\h \w\[\033[0;32m\]\$(parse_git_branch) \`if [ \"$EXIT\" = 0 ]; then echo -e '\[\e[01;32m\]:)'; else echo -e '\[\e[01;31m\]:('; fi\` \n\[\033[0;32m\]└─\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\] ▶\[\033[0m\] "
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment