Changed Agnoster theme for more modularity

The agnoster theme now supports:

* Setting color for all kinds of elements, by setting an appropiate config variable to the color name in your zshrc
  Example: AGNOSTER_GIT_DIRTY_BG=red # Set the git prompt background color to red for dirty repos
* Allowing to separate the git root and the relative path in your prompt by setting AGNOSTER_GIT_INLINE to 'true'
  You will then have a segment for the git root (ie. ~/.oh-my-zsh) followed by the existing git branch segment (ie. master) and
  finally the relative directory path (ie. themes)
* By setting AGNOSTER_STATUS_RETVAL_NUMERIC to 'true', The return value in the status prompt will become a number instead of a cross.
This commit is contained in:
Kilobyte22 2014-12-23 18:12:30 +01:00
commit 74bc2f38bc

View file

@ -22,6 +22,50 @@
# jobs are running in this shell will all be displayed automatically when # jobs are running in this shell will all be displayed automatically when
# appropriate. # appropriate.
### Theme Configuration Initialization
#
# Override these settings in your ~/.zshrc
# Current working directory
: ${AGNOSTER_DIR_FG:=black}
: ${AGNOSTER_DIR_BG:=blue}
# user@host
: ${AGNOSTER_CONTEXT_FG:=default}
: ${AGNOSTER_CONTEXT_BG:=black}
# Git related
: ${AGNOSTER_GIT_CLEAN_FG:=black}
: ${AGNOSTER_GIT_CLEAN_BG:=green}
: ${AGNOSTER_GIT_DIRTY_FG:=black}
: ${AGNOSTER_GIT_DIRTY_BG:=orange}
# Mercurial related
: ${AGNOSTER_HG_NEWFILE_FG:=white}
: ${AGNOSTER_HG_NEWFILE_BG:=red}
: ${AGNOSTER_HG_CHANGED_FG:=black}
: ${AGNOSTER_HG_CHANGED_BG:=red}
: ${AGNOSTER_HG_CLEAN_FG:=black}
: ${AGNOSTER_HG_CLEAN_BG:=green}
# VirtualEnv colors
: ${AGNOSTER_VENV_FG:=blue}
: ${AGNOSTER_VENV_BG:=black}
# Status symbols
: ${AGNOSTER_STATUS_RETVAL_FG:=red}
: ${AGNOSTER_STATUS_ROOT_FG:=yellow}
: ${AGNOSTER_STATUS_JOB_FG:=cyan}
: ${AGNOSTER_STATUS_BG:=black}
## Non-Color settings - set to 'true' to enable
# Show the actual numeric return value rather than a cross symbol.
: ${AGNOSTER_STATUS_RETVAL_NUMERIC:=false}
# Show git working dir in the style "/git/root   master  relative/dir" instead of "/git/root/relative/dir   master"
: ${AGNOSTER_GIT_INLINE:=false}
### Segment drawing ### Segment drawing
# A few utility functions to make it easy and re-usable to draw segmented prompts # A few utility functions to make it easy and re-usable to draw segmented prompts
@ -61,10 +105,18 @@ prompt_end() {
# Context: user@hostname (who am I and where am I) # Context: user@hostname (who am I and where am I)
prompt_context() { prompt_context() {
if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
prompt_segment black default "%(!.%{%F{yellow}%}.)$USER@%m" prompt_segment "$AGNOSTER_CONTEXT_BG" "$AGNOSTER_CONTEXT_FG" "%(!.%{%F{yellow}%}.)$USER@%m"
fi fi
} }
prompt_git_relative() {
local repo_root=$(git rev-parse --show-toplevel)
local path_in_repo=$(pwd | sed "s/^$(echo "$repo_root" | sed 's:/:\\/:g;s/\$/\\$/g')//;s:^/::;s:/$::;")
if [[ $path_in_repo != '' ]]; then
prompt_segment "$AGNOSTER_DIR_BG" "$AGNOSTER_DIR_FG" "$path_in_repo"
fi;
}
# Git: branch/detached head, dirty status # Git: branch/detached head, dirty status
prompt_git() { prompt_git() {
local ref dirty mode repo_path local ref dirty mode repo_path
@ -74,9 +126,9 @@ prompt_git() {
dirty=$(parse_git_dirty) dirty=$(parse_git_dirty)
ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git show-ref --head -s --abbrev |head -n1 2> /dev/null)" ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git show-ref --head -s --abbrev |head -n1 2> /dev/null)"
if [[ -n $dirty ]]; then if [[ -n $dirty ]]; then
prompt_segment yellow black prompt_segment "$AGNOSTER_GIT_DIRTY_BG" "$AGNOSTER_GIT_DIRTY_FG"
else else
prompt_segment green black prompt_segment "$AGNOSTER_GIT_CLEAN_BG" "$AGNOSTER_GIT_CLEAN_FG"
fi fi
if [[ -e "${repo_path}/BISECT_LOG" ]]; then if [[ -e "${repo_path}/BISECT_LOG" ]]; then
@ -99,6 +151,7 @@ prompt_git() {
zstyle ':vcs_info:*' actionformats ' %u%c' zstyle ':vcs_info:*' actionformats ' %u%c'
vcs_info vcs_info
echo -n "${ref/refs\/heads\// }${vcs_info_msg_0_%% }${mode}" echo -n "${ref/refs\/heads\// }${vcs_info_msg_0_%% }${mode}"
[[ $AGNOSTER_GIT_INLINE == 'true' ]] && prompt_git_relative
fi fi
} }
@ -108,15 +161,15 @@ prompt_hg() {
if $(hg prompt >/dev/null 2>&1); then if $(hg prompt >/dev/null 2>&1); then
if [[ $(hg prompt "{status|unknown}") = "?" ]]; then if [[ $(hg prompt "{status|unknown}") = "?" ]]; then
# if files are not added # if files are not added
prompt_segment red white prompt_segment "$AGNOSTER_HG_NEWFILE_BG" "$AGNOSTER_HG_NEWFILE_FG"
st='±' st='±'
elif [[ -n $(hg prompt "{status|modified}") ]]; then elif [[ -n $(hg prompt "{status|modified}") ]]; then
# if any modification # if any modification
prompt_segment yellow black prompt_segment "$AGNOSTER_HG_CHANGED_BG" "$AGNOSTER_HG_CHANGED_FG"
st='±' st='±'
else else
# if working copy is clean # if working copy is clean
prompt_segment green black prompt_segment "$AGNOSTER_HG_CLEAN_BG" "$AGNOSTER_HG_CLEAN_FG"
fi fi
echo -n $(hg prompt "☿ {rev}@{branch}") $st echo -n $(hg prompt "☿ {rev}@{branch}") $st
else else
@ -124,13 +177,13 @@ prompt_hg() {
rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g') rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g')
branch=$(hg id -b 2>/dev/null) branch=$(hg id -b 2>/dev/null)
if `hg st | grep -q "^\?"`; then if `hg st | grep -q "^\?"`; then
prompt_segment red black prompt_segment "$AGNOSTER_HG_NEWFILE_BG" "$AGNOSTER_HG_NEWFILE_FG"
st='±' st='±'
elif `hg st | grep -q "^(M|A)"`; then elif `hg st | grep -q "^(M|A)"`; then
prompt_segment yellow black prompt_segment "$AGNOSTER_HG_CHANGED_BG" "$AGNOSTER_HG_CHANGED_FG"
st='±' st='±'
else else
prompt_segment green black prompt_segment "$AGNOSTER_HG_CLEAN_BG" "$AGNOSTER_HG_CLEAN_FG"
fi fi
echo -n "☿ $rev@$branch" $st echo -n "☿ $rev@$branch" $st
fi fi
@ -139,14 +192,19 @@ prompt_hg() {
# Dir: current working directory # Dir: current working directory
prompt_dir() { prompt_dir() {
prompt_segment blue black '%~' if [[ $AGNOSTER_GIT_INLINE == 'true' ]] && $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
# Git repo and inline path enabled, hence only show the git root
prompt_segment "$AGNOSTER_DIR_BG" "$AGNOSTER_DIR_FG" "$(git rev-parse --show-toplevel | sed "s:^$HOME:~:")"
else
prompt_segment "$AGNOSTER_DIR_BG" "$AGNOSTER_DIR_FG" '%~'
fi
} }
# Virtualenv: current working virtualenv # Virtualenv: current working virtualenv
prompt_virtualenv() { prompt_virtualenv() {
local virtualenv_path="$VIRTUAL_ENV" local virtualenv_path="$VIRTUAL_ENV"
if [[ -n $virtualenv_path && -n $VIRTUAL_ENV_DISABLE_PROMPT ]]; then if [[ -n $virtualenv_path && -n $VIRTUAL_ENV_DISABLE_PROMPT ]]; then
prompt_segment blue black "(`basename $virtualenv_path`)" prompt_segment "$AGNOSTER_VENV_BG" "$AGNOSTER_VENV_FG" "(`basename $virtualenv_path`)"
fi fi
} }
@ -157,11 +215,15 @@ prompt_virtualenv() {
prompt_status() { prompt_status() {
local symbols local symbols
symbols=() symbols=()
[[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}✘" if [[ $AGNOSTER_STATUS_RETVAL_NUMERIC == 'true' ]]; then
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡" [[ $RETVAL -ne 0 ]] && symbols+="%{%F{$AGNOSTER_STATUS_RETVAL_FG}%}$RETVAL"
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}⚙" else
[[ $RETVAL -ne 0 ]] && symbols+="%{%F{$AGNOSTER_STATUS_RETVAL_FG}%}✘"
fi
[[ $UID -eq 0 ]] && symbols+="%{%F{$AGNOSTER_STATUS_ROOT_FG}%}⚡"
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{$AGNOSTER_STATUS_JOB_FG}%}⚙"
[[ -n "$symbols" ]] && prompt_segment black default "$symbols" [[ -n "$symbols" ]] && prompt_segment "$AGNOSTER_STATUS_BG" default "$symbols"
} }
## Main prompt ## Main prompt