Created
July 18, 2012 06:49
-
-
Save hadashiA/3134677 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# \e[XX;Ym | |
# 3X for foreground, 4X for background | |
# 0:black,1:red,2:green,3:yellow,4:blue,5:magenta,6:cyan,7:white | |
# ;0/;1 for regular/bold | |
# \[...\] needed to tell bash to ignore in calculating length | |
prompt_c_grey='\[\e[30;1m\]' | |
prompt_c_green='\[\e[32;1m\]' | |
prompt_c_yellow='\[\e[33;1m\]' | |
prompt_c_blue='\[\e[34;1m\]' | |
prompt_c_magenta='\[\e[35;1m\]' | |
prompt_c_cyan='\[\e[36;1m\]' | |
prompt_c_reset='\[\e[0m\]' | |
function prompt_string { | |
# previous command return code | |
local rc=${1:-$?} | |
printf '%s' $prompt_c_green | |
# add username to prompt if it doesn't match ME | |
if [ "$USER" != "$ME" ] ; then | |
printf '\u@' | |
fi | |
# add hostname | |
printf "\h" | |
# separator | |
printf '%s:' $prompt_c_grey | |
# add path | |
printf '%s\w' $prompt_c_blue | |
# add git info | |
if true ; then | |
printf ' %s[' $prompt_c_grey | |
git status 2>/dev/null | \ | |
while read -r line; do | |
local c=$((c+1)) | |
if ((c == 1)); then | |
if [[ "$line" =~ ^'# Not currently on any branch.' ]] ; then | |
local branch='(none)' | |
else | |
local branch=$(echo $line | awk '{ print $4 }') | |
fi | |
printf '%s%s' $prompt_c_yellow $branch | |
elif [[ "$line" =~ ^'# Unmerged paths:' ]] ; then | |
printf '%s!' $prompt_c_cyan | |
elif [[ "$line" =~ ^'# Changes to be committed:' ]] ; then | |
printf '%s~' $prompt_c_cyan | |
elif [[ "$line" =~ ^'# Changed but not updated:' ]] ; then | |
printf '%s*' $prompt_c_cyan | |
fi | |
done | |
printf '%s]' $prompt_c_grey | |
fi | |
# add return code and close | |
printf ' %s%s\$%s ' $prompt_c_grey $rc $prompt_c_reset | |
} | |
PROMPT_COMMAND=prompt_command | |
prompt_command() { PS1=$(prompt_string $?); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment