Skip to content

Instantly share code, notes, and snippets.

@amejiarosario
Created June 14, 2012 13:29
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 amejiarosario/2930289 to your computer and use it in GitHub Desktop.
Save amejiarosario/2930289 to your computer and use it in GitHub Desktop.
2 lines prompt, git branch and time
# A two-line colored Bash prompt (PS1) with Git branch and a line decoration
# which adjusts automatically to the width of the terminal.
# Screenshot: http://img194.imageshack.us/img194/2154/twolineprompt.png
# Michal Kottman, 2012
RESET="\[\033[0m\]"
RED="\[\033[0;31m\]"
GREEN="\[\033[01;32m\]"
BLUE="\[\033[01;34m\]"
YELLOW="\[\033[0;33m\]"
PS_LINE=`printf -- '- %.0s' {1..200}`
function parse_git_branch {
PS_GIT_BRANCH=''
PS_FILL=${PS_LINE:0:$COLUMNS}
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
PS_GIT_BRANCH="(${ref#refs/heads/}) "
}
PROMPT_COMMAND=parse_git_branch
PS_INFO="$GREEN\u@\h$RESET:$BLUE\w"
PS_GIT="$YELLOW\$PS_GIT_BRANCH"
PS_TIME="\[\033[\$((COLUMNS-10))G\] $RED[\t]"
export PS1="\${PS_FILL}\[\033[0G\]${PS_INFO} ${PS_GIT}${PS_TIME}\n${RESET}\$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment