- Copy the above code
- Insert it into your
~/.bash_profile
- Save, now all terminal windows from now on will have the awesomeness
Created
August 1, 2012 13:34
-
-
Save balupton/3226860 to your computer and use it in GitHub Desktop.
Prompt Command with time, user, host, location, git branch, and git status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
# Colors | |
export RED="\[\033[0;31m\]" | |
export RED_BOLD="\[\033[01;31m\]" | |
export BLUE="\[\033[0;34m\]" | |
export CYAN='\[\e[0;36m\]' | |
export PURPLE='\[\e[0;35m\]' | |
export GREEN="\[\033[0;32m\]" | |
export YELLOW="\[\033[0;33m\]" | |
export BLACK="\[\033[0;38m\]" | |
export NO_COLOUR="\[\033[0m\]" | |
export C_RESET='\[\e[0m\]' | |
export C_TIME=$GREEN | |
export C_USER=$BLUE | |
export C_PATH=$YELLOW | |
export C_GIT_CLEAN=$CYAN | |
export C_GIT_DIRTY=$PURPLE | |
### | |
# Functions | |
# Function to assemble the Git part of our prompt. | |
function git_prompt { | |
if ! git rev-parse --git-dir > /dev/null 2>&1; then | |
return 0 | |
fi | |
echo ":$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')" | |
} | |
function git_prompt_color { | |
if ! git rev-parse --git-dir > /dev/null 2>&1; then | |
return 0 | |
fi | |
git_branch=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p') | |
if git diff --quiet 2>/dev/null >&2; then | |
git_color="${C_GIT_CLEAN}" | |
else | |
git_color="${C_GIT_DIRTY}" | |
fi | |
echo ":${git_color}${git_branch}${C_RESET}" | |
} | |
### | |
# Customisation | |
# Terminal Prefix | |
function prompt_command { | |
local separator=':' | |
local time=$(date +%H:%M:%S) | |
local path=${PWD/$HOME/~} | |
local user="${USER}@${HOSTNAME}" | |
local title="${user}${separator}${path}$(git_prompt)" | |
local prefix="${C_TIME}${time}${C_RESET}${separator}${C_USER}${user}${C_RESET}${separator}${C_PATH}${path}${C_RESET}$(git_prompt_color)\$ " | |
export PS1="${prefix}" | |
echo -ne "\033]0;${title}\007" | |
} | |
export PROMPT_COMMAND=prompt_command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment