Skip to content

Instantly share code, notes, and snippets.

@wernerb
Last active February 12, 2016 20:56
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 wernerb/5ebe6e40c0f5ecb0552d to your computer and use it in GitHub Desktop.
Save wernerb/5ebe6e40c0f5ecb0552d to your computer and use it in GitHub Desktop.
Theme for ZSH based on bureau theme. 2 lines, features time and git status / branch.
# oh-my-zsh w-buck Bureau Theme
### CUSTOM
_COL="red"
_HR="(" #❯
_HL=")" #❮
_LEFT="%{$fg[$_COL]%}$_HR%{$reset_color%}"
_RIGHT="%{$fg[$_COL]%}$_HL%{$reset_color%}"
### NVM
ZSH_THEME_NVM_PROMPT_PREFIX="%B⬡%b "
ZSH_THEME_NVM_PROMPT_SUFFIX=" "
### AWS ☁(cloud)
ZSH_THEME_AWS_PROMPT_PREFIX="%{$fg[$_COL]%}\u2601 $_HR%{$reset_color%}"
ZSH_THEME_AWS_PROMPT_SUFFIX="%{$fg[$_COL]%}$_HL%{$reset_color%} "
### Git [±master ▾●]
ZSH_THEME_GIT_PROMPT_PREFIX="$_LEFT%{$fg_bold[green]%}±%{$reset_color%}%{$fg_bold[white]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}$_RIGHT"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[green]%}✓%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg[cyan]%}▴%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_BEHIND="%{$fg[magenta]%}▾%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_STAGED="%{$fg_bold[green]%}●%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg_bold[yellow]%}●%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}●%{$reset_color%}"
bureau_git_branch () {
ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
echo "${ref#refs/heads/}"
}
bureau_git_status () {
_INDEX=$(command git status --porcelain -b 2> /dev/null)
_STATUS=""
if $(echo "$_INDEX" | grep '^[AMRD]. ' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STAGED"
fi
if $(echo "$_INDEX" | grep '^.[MTD] ' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNSTAGED"
fi
if $(echo "$_INDEX" | grep -E '^\?\? ' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED"
fi
if $(echo "$_INDEX" | grep '^UU ' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNMERGED"
fi
if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STASHED"
fi
if $(echo "$_INDEX" | grep '^## .*ahead' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_AHEAD"
fi
if $(echo "$_INDEX" | grep '^## .*behind' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_BEHIND"
fi
if $(echo "$_INDEX" | grep '^## .*diverged' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_DIVERGED"
fi
echo $_STATUS
}
bureau_git_prompt () {
local _branch=$(bureau_git_branch)
local _status=$(bureau_git_status)
local _result=""
if [[ "${_branch}x" != "x" ]]; then
_result="$ZSH_THEME_GIT_PROMPT_PREFIX$_branch"
if [[ "${_status}x" != "x" ]]; then
_result="$_result $_status"
fi
_result="$_result$ZSH_THEME_GIT_PROMPT_SUFFIX"
fi
echo $_result
}
aws_prompt () {
if [[ $plugins == *"aws"* ]]; then
if [ -n "$(agp)" ]; then
echo -e "$ZSH_THEME_AWS_PROMPT_PREFIX$(agp)$ZSH_THEME_AWS_PROMPT_SUFFIX"
fi
fi
}
_PATH="%~%{$reset_color%}"
if [[ $EUID -eq 0 ]]; then
_USERNAME="┌─$_LEFT$fg[red]%n%{$fg[$_COL]%}@%{$reset_color%}%m$_RIGHT-$_LEFT$_PATH$_RIGHT"
_LIBERTY="└─$fg[red]❯"
else
case $(hostname) in
"Apollo"* )
_USERNAME="┌─$_LEFT%n%{$fg[$_COL]%}$_RIGHT-$_LEFT$_PATH$_RIGHT"
_LIBERTY="└─❯"
;;
* )
_USERNAME="┌─$_LEFT%n%{$fg[$_COL]%}@%{$reset_color%}%m$_RIGHT-$_LEFT$_PATH$_RIGHT"
_LIBERTY="└─❯"
;;
esac
fi
_USERNAME="$_USERNAME%{$reset_color%}"
_LIBERTY="$_LIBERTY%{$reset_color%}"
get_space () {
local STR=$1$2
local zero='%([BSUbfksu]|([FB]|){*})'
local LENGTH=${#${(S%%)STR//$~zero/}}
local SPACES=""
(( LENGTH = ${COLUMNS} - $LENGTH - 1))
for i in {0..$LENGTH}
do
SPACES="$SPACES "
done
if [ $LENGTH -le 0 ]; then
print -rP "$1"
else
print -rP "$1$SPACES$2"
fi
}
_1LEFT="$_USERNAME"
_1RIGHT="$_LEFT%*$_RIGHT "
bureau_precmd () {
get_space $_1LEFT $_1RIGHT
}
setopt prompt_subst
PROMPT='$_LIBERTY '
rprompt_ifempty () {
#Put in return code if necessary
local _return_status="%(?..%? %{$fg[red]%}↵%{$reset_color%})"
#Put in various tool prompts
local _TOOLS="$(aws_prompt)$(nvm_prompt_info)$(bureau_git_prompt)"
case "$_TOOLS" in
*[!\ ]*) echo "${_return_status} $_TOOLS";;
*) echo "${_return_status}";; #127 ↵
esac
}
RPROMPT='$(rprompt_ifempty)'
autoload -U add-zsh-hook
add-zsh-hook precmd bureau_precmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment