Skip to content

Instantly share code, notes, and snippets.

@jeandat
Last active January 16, 2017 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeandat/862bd6a9623f83e35e70fd0efdb8e8a4 to your computer and use it in GitHub Desktop.
Save jeandat/862bd6a9623f83e35e70fd0efdb8e8a4 to your computer and use it in GitHub Desktop.
My Customized Bash Prompt
# Get current git branch
function parse_git_branch () {
       git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
BLACK="\[\033[0;30m\]"
RED="\[\033[0;31m\]"
GREEN="\[\033[0;32m\]"
YELLOW="\[\033[0;33m\]"
BLUE="\[\033[0;34m\]"
MAGENTA="\[\033[0;35m\]"
CYAN="\[\033[0;36m\]"
WHITE="\[\033[0;37m\]"
NO_COLOR="\[\033[0m\]"
PS1="$GREEN\W$YELLOW\$(parse_git_branch)$NO_COLOR 🍺  $CYAN"
# Reset formatting after ENTER key
# http://unix.stackexchange.com/questions/146145/how-do-i-stop-a-bash-shell-ps1-color-to-stop-at-the-end-of-the-command
# https://seasonofcode.com/posts/debug-trap-and-prompt_command-in-bash.html
AT_PROMPT=1 
# This will run before any command is executed.
function PreCommand() {
  if [ -z "$AT_PROMPT" ]; then
    return
  fi
  unset AT_PROMPT
  [[ -t 1 ]] && tput sgr0
}
trap "PreCommand" DEBUG
# This will run after the execution of the previous full command line.  We don't
# want it to execute when first starting a bash session (i.e., at the first prompt).
FIRST_PROMPT=1
function PostCommand() {
  AT_PROMPT=1
  if [ -n "$FIRST_PROMPT" ]; then
    unset FIRST_PROMPT
    return
  fi
}
PROMPT_COMMAND="PostCommand"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment