Created
January 25, 2013 17:22
-
-
Save ganglio/4636266 to your computer and use it in GitHub Desktop.
ZSH: Prompt Theme
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
##Ganglio theme | |
# A couple of definition | |
OPEN_SQUARE="%{$reset_color%}%{$fg[cyan]%}[%{$reset_color%}" | |
CLOSE_SQUARE="%{$reset_color%}%{$fg[cyan]%}]%{$reset_color%}" | |
TL_ANGLE="%{$reset_color%}%{$fg[cyan]%}┌%{$reset_color%}" | |
BL_ANGLE="%{$reset_color%}%{$fg[cyan]%}└%{$reset_color%}" | |
V_BAR="%{$reset_color%}%{$fg[cyan]%}│%{$reset_color%}" | |
VR_BAR="%{$reset_color%}%{$fg[cyan]%}├%{$reset_color%}" | |
AT_SIGN="%{$reset_color%}%{$fg[cyan]%}@%{$reset_color%}" | |
DASH_SIGN="%{$reset_color%}%{$fg[cyan]%}-%{$reset_color%}" | |
COLUMN_SIGN="%{$reset_color%}%{$fg[cyan]%}:%{$reset_color%}" | |
MOVE_UP="\x1B[A" | |
HOSTINFO="%{$OPEN_SQUARE%}%{$fg_bold[green]%}%n%{$AT_SIGN%}%{$fg_bold[green]%}%M%{$COLUMN_SIGN%}%{$fg_bold[green]%}%~%{$CLOSE_SQUARE%}" | |
# Where we do the magic | |
function ganglio_prompt { | |
# If the current folder is a git repo... | |
local isGIT=$(git rev-parse --git-dir 2> /dev/null) | |
if [ -n "$isGIT" ]; then | |
# ... extract branch and remote... | |
local GITB=$(git branch --no-color 2> /dev/null | sed -e "/^[^*]/d" -e "s/* \(.*\)/\1/") | |
local GITR=$(git config --get "branch.$GITB.remote" 2> /dev/null) | |
if [ -z $GITB ]; then | |
GITB="$fg[red]no commit yet" | |
GITR="" | |
fi | |
[ $GITR ] && GITR=$AT_SIGN"%{$fg_bold[yellow]%}"$GITR | |
local GITBR="\n%{$VR_BAR%}%{$OPEN_SQUARE%}%{$fg_bold[yellow]%}%{$GITB%}%{$GITR%}%{$CLOSE_SQUARE%}" | |
# ... then get the folder status (changed, untracked, etc.)... | |
GITSC=$(git status -s 2> /dev/null | awk '{print $1;}' | sort | uniq -c | sed -e 's/??/U/g' -Ee 's/([0-9]*)\ ([A-Z])/\1\2/' -e 's/\ //g') | |
[ $GITSC ] && local GITS="%{$OPEN_SQUARE%}%{$fg_bold[yellow]%}$GITSC%{$CLOSE_SQUARE%}" | |
# ... then how many commit we are ahead of the remote... | |
GITAHC=$(git status 2> /dev/null | grep ahead | awk '{print $9;}') | |
[ $GITAHC ] && local GITAH="%{$OPEN_SQUARE%}%{$fg_bold[red]%}$GITAHC%{$CLOSE_SQUARE%}" | |
# ... and finally how many stashes we have | |
GITSTC=$(git stash list 2> /dev/null | wc -l) | |
[ $GITSTC != "0" ] && local GITST="%{$OPEN_SQUARE%}%{$fg_bold[magenta]%}$GITSTC%{$CLOSE_SQUARE%}" | |
# Mix the last three together | |
GIT_INFO_ARRAY=($GITS $GITAH $GITST) | |
GIT_INFO=${(j:-:)GIT_INFO_ARRAY} | |
[ $GIT_INFO ] && GIT_INFO="\n%{$VR_BAR%}"$(echo $GIT_INFO | sed -e "s/-/$DASH_SIGN/g") | |
fi | |
# if the current folder have a test subfolder it might be testable with vows (my favourite) | |
if [ -d "test" ]; then | |
VOWS=$(vows --dot-matrix 2>&1) | |
ERROR=$(echo $VOWS | egrep "^Error") | |
if [ $ERROR ]; then | |
local VOWSC="$fg[red]$ERROR$reset_color" | |
else | |
VOWS=$(echo $VOWS | head -n 1 | sed -e 's/ *$//g') | |
FIRST=$(echo $VOWS | awk '{print $1}') | |
[ $FIRST ] && VOWSC=$(echo $VOWS | sed -e "s/·/$fg[green]·$reset_color/g" -e "s/✗/$fg_bold[red]✗$reset_color/g") | |
fi | |
[ $VOWSC ] && local VOWSS="\n%{$VR_BAR%}%{$OPEN_SQUARE%}%{$VOWSC%}%{$CLOSE_SQUARE%}" | |
fi | |
# adding something on the other side of the terminal | |
local GRPROMPT | |
GRPROMPT=$(ganglio_rprompt) | |
filler_str=$(filler $HOSTINFO $GRPROMPT ' ') | |
HOSTINFO+=$filler_str$GRPROMPT | |
# that's all folks :D | |
echo "\n%{$TL_ANGLE%}%{$HOSTINFO%}$GITBR$GIT_INFO$VOWSS\n%{$BL_ANGLE%}%{$fg[cyan]%}>%{$reset_color%} " | |
} | |
function filler { | |
local str1=$1 | |
local str2=$2 | |
local sep=$3 | |
local i_width1 | |
i_width1=${(S)str1//\%\{*\%\}} | |
i_width1=${#${(%)i_width1}} | |
local i_width2 | |
i_width2=${(S)str2//\%\{*\%\}} | |
i_width2=${#${(%)i_width2}} | |
local i_filler | |
i_filler=$(( $COLUMNS - $i_width1 - $i_width2 )) | |
local filler_str | |
filler_str=${(l:${i_filler}::¬:)} | |
filler_str=$(echo $filler_str | sed -e "s/¬/$sep/g") | |
echo $filler_str | |
} | |
# this is just a testing function used to print the current time. you can change it to whatever you like | |
function ganglio_rprompt { | |
echo "$OPEN_SQUARE$fg_bold[yellow]"$(date +%F)"$CLOSE_SQUARE" | |
} | |
PROMPT='$(ganglio_prompt)' | |
[ -f ~/.zsh_proxy ] && source ~/.zsh_proxy | |
# vim:set ft=zsh: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment