Skip to content

Instantly share code, notes, and snippets.

@jbnv
Last active July 3, 2017 13:14
Show Gist options
  • Select an option

  • Save jbnv/78ce47382faf454553ef to your computer and use it in GitHub Desktop.

Select an option

Save jbnv/78ce47382faf454553ef to your computer and use it in GitHub Desktop.
My standard shell prompt script. Show current git branch in the prompt, if there is one. Show current path in the prompt. Replace home path with "~". Replace "/var/www" with "%".
parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
parse_pwd () {
pwd | sed -e 's#/var/www/#%#' | sed -e 's#/home/myusername#~#'
}
prompt () {
echo "$BRANCH_COLOR\$(parse_git_branch)$USERNAME_COLOR`whoami`$PATH_COLOR\$(parse_pwd)$PROMPT_COLOR "
}
USERNAME_COLOR="\[\033[0;37m\]" #gray
BRANCH_COLOR="\[\033[0;33m\]" #yellow
PATH_COLOR="\[\033[1;32m\]" #green; bold
PROMPT_COLOR="\[\033[0m\]" #none (white)
PS1="$(prompt)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment