Skip to content

Instantly share code, notes, and snippets.

@dandeveloper
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save dandeveloper/3fca71a5c78f7480ce57 to your computer and use it in GitHub Desktop.

Select an option

Save dandeveloper/3fca71a5c78f7480ce57 to your computer and use it in GitHub Desktop.
Mostrar branch atual do git no terminal
#===========================================
# Váriavies com as Cores
#===========================================
NONE="\[\033[0m\]" # Eliminar as Cores, deixar padrão)
## Cores de Fonte
K="\[\033[0;30m\]" # Black (Preto)
R="\[\033[0;31m\]" # Red (Vermelho)
G="\[\033[0;32m\]" # Green (Verde)
Y="\[\033[0;33m\]" # Yellow (Amarelo)
B="\[\033[0;34m\]" # Blue (Azul)
M="\[\033[0;35m\]" # Magenta (Vermelho Claro)
C="\[\033[0;36m\]" # Cyan (Ciano - Azul Claro)
W="\[\033[0;37m\]" # White (Branco)
## Efeito Negrito (bold) e cores
BK="\[\033[1;30m\]" # Bold+Black (Negrito+Preto)
BR="\[\033[1;31m\]" # Bold+Red (Negrito+Vermelho)
BG="\[\033[1;32m\]" # Bold+Green (Negrito+Verde)
BY="\[\033[1;33m\]" # Bold+Yellow (Negrito+Amarelo)
BB="\[\033[1;34m\]" # Bold+Blue (Negrito+Azul)
BM="\[\033[1;35m\]" # Bold+Magenta (Negrito+Vermelho Claro)
BC="\[\033[1;36m\]" # Bold+Cyan (Negrito+Ciano - Azul Claro)
BW="\[\033[1;37m\]" # Bold+White (Negrito+Branco)
## Cores de fundo (backgroud)
BGK="\[\033[40m\]" # Black (Preto)
BGR="\[\033[41m\]" # Red (Vermelho)
BGG="\[\033[42m\]" # Green (Verde)
BGY="\[\033[43m\]" # Yellow (Amarelo)
BGB="\[\033[44m\]" # Blue (Azul)
BGM="\[\033[45m\]" # Magenta (Vermelho Claro)
BGC="\[\033[46m\]" # Cyan (Ciano - Azul Claro)
BGW="\[\033[47m\]" # White (Branco)
# Mostra branch atual do git no terminal
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\[\033[0;31m\]\u\[\033[0;37m\]@\[\033[0;36m\]\h \[\033[0;37m\]\W\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "
@dandeveloper
Copy link
Author

Notes:

  • Depending on configuration changes you may have made previously you may already have a PS1 variable being exported. In this case you will need to add $(parse_git_branch) somewhere in the existing value.
  • The [\033[32m] parts set the color of the branch text. If you prefer another color check online for a reference on valid values.
  • The \ in $(parse_git_branch) is important to ensure the function is called each time the prompt is displayed; without it, the displayed branch name would not be updated when, for example, checking out a different branch or moving in and out of a Git repository directory.

Reference: http://martinfitzpatrick.name/article/add-git-branch-name-to-terminal-prompt-mac/

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