agnoster: Added option to allow light/dark

Added option to customize the foreground color. For light themes, set:
`PRIMARY_FG=white` in your zshrc.
This commit is contained in:
Pedro Matias 2017-08-27 17:46:14 -04:00
parent d848c94804
commit a635b2b4d4

View File

@ -29,6 +29,9 @@
# 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
CURRENT_BG='NONE' CURRENT_BG='NONE'
if [[ -z "$PRIMARY_FG" ]]; then
PRIMARY_FG=black
fi
# Special Powerline characters # Special Powerline characters
@ -80,7 +83,7 @@ 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 $PRIMARY_FG default "%(!.%{%F{yellow}%}.)$USER@%m"
fi fi
} }
@ -99,9 +102,9 @@ prompt_git() {
dirty=$(parse_git_dirty) dirty=$(parse_git_dirty)
ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git rev-parse --short HEAD 2> /dev/null)" ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git rev-parse --short HEAD 2> /dev/null)"
if [[ -n $dirty ]]; then if [[ -n $dirty ]]; then
prompt_segment yellow black prompt_segment yellow $PRIMARY_FG
else else
prompt_segment green black prompt_segment green $PRIMARY_FG
fi fi
if [[ -e "${repo_path}/BISECT_LOG" ]]; then if [[ -e "${repo_path}/BISECT_LOG" ]]; then
@ -134,15 +137,15 @@ prompt_bzr() {
status_all=`bzr status | head -n1 | wc -m` status_all=`bzr status | head -n1 | wc -m`
revision=`bzr log | head -n2 | tail -n1 | sed 's/^revno: //'` revision=`bzr log | head -n2 | tail -n1 | sed 's/^revno: //'`
if [[ $status_mod -gt 0 ]] ; then if [[ $status_mod -gt 0 ]] ; then
prompt_segment yellow black prompt_segment yellow $PRIMARY_FG
echo -n "bzr@"$revision "✚ " echo -n "bzr@"$revision "✚ "
else else
if [[ $status_all -gt 0 ]] ; then if [[ $status_all -gt 0 ]] ; then
prompt_segment yellow black prompt_segment yellow $PRIMARY_FG
echo -n "bzr@"$revision echo -n "bzr@"$revision
else else
prompt_segment green black prompt_segment green $PRIMARY_FG
echo -n "bzr@"$revision echo -n "bzr@"$revision
fi fi
fi fi
@ -160,11 +163,11 @@ prompt_hg() {
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 yellow $PRIMARY_FG
st='±' st='±'
else else
# if working copy is clean # if working copy is clean
prompt_segment green black prompt_segment green $PRIMARY_FG
fi fi
echo -n $(hg prompt "☿ {rev}@{branch}") $st echo -n $(hg prompt "☿ {rev}@{branch}") $st
else else
@ -172,13 +175,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 red $PRIMARY_FG
st='±' st='±'
elif `hg st | grep -q "^[MA]"`; then elif `hg st | grep -q "^[MA]"`; then
prompt_segment yellow black prompt_segment yellow $PRIMARY_FG
st='±' st='±'
else else
prompt_segment green black prompt_segment green $PRIMARY_FG
fi fi
echo -n "☿ $rev@$branch" $st echo -n "☿ $rev@$branch" $st
fi fi
@ -187,14 +190,14 @@ prompt_hg() {
# Dir: current working directory # Dir: current working directory
prompt_dir() { prompt_dir() {
prompt_segment blue black '%~' prompt_segment blue $PRIMARY_FG '%~'
} }
# 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 blue $PRIMARY_FG "(`basename $virtualenv_path`)"
fi fi
} }
@ -209,7 +212,7 @@ prompt_status() {
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡" [[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡"
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}⚙" [[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}⚙"
[[ -n "$symbols" ]] && prompt_segment black default "$symbols" [[ -n "$symbols" ]] && prompt_segment $PRIMARY_FG default "$symbols"
} }
## Main prompt ## Main prompt