Skip to content

Instantly share code, notes, and snippets.

@teamshortcut
Last active July 6, 2020 09:38
Show Gist options
  • Select an option

  • Save teamshortcut/1ae5c5715518a77ce032a1cfacf79e97 to your computer and use it in GitHub Desktop.

Select an option

Save teamshortcut/1ae5c5715518a77ce032a1cfacf79e97 to your computer and use it in GitHub Desktop.
Custom shell prompt (PS1)
# [username@hostname ~/path (git branch)]$
# [bluepurpleblue yellow orange]$
# Outside []$ is green if previous command is successful (exit code = 0) and red otherwise
# Add https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh to your home directory
source ~/.git-prompt.sh
export PS1='$(exitcode=$?; if [[ $exitcode == 0 ]]; then printf "\[\e[32m\][\[\e[m\]"; else printf "\[\e[31m\][\[\e[m\]"; fi; printf "\[\e[34m\]\u\[\e[m\]\[\e[95m\]@\[\e[m\]\[\e[34m\]\h\[\e[m\] \[\e[33m\]\w\[\e[m\]\[\e[91m\]$(__git_ps1 " (%s)")\[\e[m\]"; if [[ $exitcode == 0 ]]; then printf "\[\e[32m\]]\$ \[\e[m\]"; else printf "\[\e[31m\]]\$ \[\e[m\]"; fi)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment