summaryrefslogtreecommitdiff
path: root/themes/agnoster.zsh-theme
diff options
context:
space:
mode:
Diffstat (limited to 'themes/agnoster.zsh-theme')
-rw-r--r--themes/agnoster.zsh-theme110
1 files changed, 95 insertions, 15 deletions
diff --git a/themes/agnoster.zsh-theme b/themes/agnoster.zsh-theme
index 8c7be6e01..8c700d06a 100644
--- a/themes/agnoster.zsh-theme
+++ b/themes/agnoster.zsh-theme
@@ -7,12 +7,19 @@
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://github.com/Lokaltog/powerline-fonts).
+# Make sure you have a recent version: the code points that Powerline
+# uses changed in 2012, and older versions will display incorrectly,
+# in confusing ways.
#
# In addition, I recommend the
# [Solarized theme](https://github.com/altercation/solarized/) and, if you're
-# using it on Mac OS X, [iTerm 2](http://www.iterm2.com/) over Terminal.app -
+# using it on Mac OS X, [iTerm 2](https://iterm2.com/) over Terminal.app -
# it has significantly better color fidelity.
#
+# If using with "light" variant of the Solarized color schema, set
+# SOLARIZED_THEME variable to "light". If you don't specify, we'll assume
+# you're using the "dark" variant.
+#
# # Goals
#
# The aim of this theme is to only show you *relevant* information. Like most
@@ -26,7 +33,28 @@
# A few utility functions to make it easy and re-usable to draw segmented prompts
CURRENT_BG='NONE'
-SEGMENT_SEPARATOR=''
+
+case ${SOLARIZED_THEME:-dark} in
+ light) CURRENT_FG='white';;
+ *) CURRENT_FG='black';;
+esac
+
+# Special Powerline characters
+
+() {
+ local LC_ALL="" LC_CTYPE="en_US.UTF-8"
+ # NOTE: This segment separator character is correct. In 2012, Powerline changed
+ # the code points they use for their special characters. This is the new code point.
+ # If this is not working for you, you probably have an old version of the
+ # Powerline-patched fonts installed. Download and install the new version.
+ # Do not submit PRs to change this unless you have reviewed the Powerline code point
+ # history and have new information.
+ # This is defined using a Unicode escape sequence so it is unambiguously readable, regardless of
+ # what font the user is viewing this source code in. Do not replace the
+ # escape sequence with a single literal character.
+ # Do not change this! Do not make it '\u2b80'; that is the old, wrong code point.
+ SEGMENT_SEPARATOR=$'\ue0b0'
+}
# Begin a segment
# Takes two arguments, background and foreground. Both can be omitted,
@@ -61,22 +89,31 @@ prompt_end() {
# Context: user@hostname (who am I and where am I)
prompt_context() {
if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
- prompt_segment black default "%(!.%{%F{yellow}%}.)$USER@%m"
+ prompt_segment black default "%(!.%{%F{yellow}%}.)%n@%m"
fi
}
# Git: branch/detached head, dirty status
prompt_git() {
+ (( $+commands[git] )) || return
+ if [[ "$(git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]]; then
+ return
+ fi
+ local PL_BRANCH_CHAR
+ () {
+ local LC_ALL="" LC_CTYPE="en_US.UTF-8"
+ PL_BRANCH_CHAR=$'\ue0a0' # 
+ }
local ref dirty mode repo_path
- repo_path=$(git rev-parse --git-dir 2>/dev/null)
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
+ repo_path=$(git rev-parse --git-dir 2>/dev/null)
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 rev-parse --short HEAD 2> /dev/null)"
if [[ -n $dirty ]]; then
prompt_segment yellow black
else
- prompt_segment green black
+ prompt_segment green $CURRENT_FG
fi
if [[ -e "${repo_path}/BISECT_LOG" ]]; then
@@ -94,16 +131,44 @@ prompt_git() {
zstyle ':vcs_info:*' get-revision true
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' stagedstr '✚'
- zstyle ':vcs_info:git:*' unstagedstr '●'
+ zstyle ':vcs_info:*' unstagedstr '●'
zstyle ':vcs_info:*' formats ' %u%c'
zstyle ':vcs_info:*' actionformats ' %u%c'
vcs_info
- echo -n "${ref/refs\/heads\// }${vcs_info_msg_0_%% }${mode}"
+ echo -n "${ref/refs\/heads\//$PL_BRANCH_CHAR }${vcs_info_msg_0_%% }${mode}"
+ fi
+}
+
+prompt_bzr() {
+ (( $+commands[bzr] )) || return
+
+ # Test if bzr repository in directory hierarchy
+ local dir="$PWD"
+ while [[ ! -d "$dir/.bzr" ]]; do
+ [[ "$dir" = "/" ]] && return
+ dir="${dir:h}"
+ done
+
+ local bzr_status status_mod status_all revision
+ if bzr_status=$(bzr status 2>&1); then
+ status_mod=$(echo -n "$bzr_status" | head -n1 | grep "modified" | wc -m)
+ status_all=$(echo -n "$bzr_status" | head -n1 | wc -m)
+ revision=$(bzr log -r-1 --log-format line | cut -d: -f1)
+ if [[ $status_mod -gt 0 ]] ; then
+ prompt_segment yellow black "bzr@$revision ✚"
+ else
+ if [[ $status_all -gt 0 ]] ; then
+ prompt_segment yellow black "bzr@$revision"
+ else
+ prompt_segment green black "bzr@$revision"
+ fi
+ fi
fi
}
prompt_hg() {
- local rev status
+ (( $+commands[hg] )) || return
+ local rev st branch
if $(hg id >/dev/null 2>&1); then
if $(hg prompt >/dev/null 2>&1); then
if [[ $(hg prompt "{status|unknown}") = "?" ]]; then
@@ -116,7 +181,7 @@ prompt_hg() {
st='±'
else
# if working copy is clean
- prompt_segment green black
+ prompt_segment green $CURRENT_FG
fi
echo -n $(hg prompt "☿ {rev}@{branch}") $st
else
@@ -126,11 +191,11 @@ prompt_hg() {
if `hg st | grep -q "^\?"`; then
prompt_segment red black
st='±'
- elif `hg st | grep -q "^(M|A)"`; then
+ elif `hg st | grep -q "^[MA]"`; then
prompt_segment yellow black
st='±'
else
- prompt_segment green black
+ prompt_segment green $CURRENT_FG
fi
echo -n "☿ $rev@$branch" $st
fi
@@ -139,7 +204,7 @@ prompt_hg() {
# Dir: current working directory
prompt_dir() {
- prompt_segment blue black '%~'
+ prompt_segment blue $CURRENT_FG '%~'
}
# Virtualenv: current working virtualenv
@@ -155,8 +220,8 @@ prompt_virtualenv() {
# - am I root
# - are there background jobs?
prompt_status() {
- local symbols
- symbols=()
+ local -a symbols
+
[[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}✘"
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡"
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}⚙"
@@ -164,14 +229,29 @@ prompt_status() {
[[ -n "$symbols" ]] && prompt_segment black default "$symbols"
}
+#AWS Profile:
+# - display current AWS_PROFILE name
+# - displays yellow on red if profile name contains 'production' or
+# ends in '-prod'
+# - displays black on green otherwise
+prompt_aws() {
+ [[ -z "$AWS_PROFILE" ]] && return
+ case "$AWS_PROFILE" in
+ *-prod|*production*) prompt_segment red yellow "AWS: $AWS_PROFILE" ;;
+ *) prompt_segment green black "AWS: $AWS_PROFILE" ;;
+ esac
+}
+
## Main prompt
build_prompt() {
RETVAL=$?
prompt_status
prompt_virtualenv
+ prompt_aws
prompt_context
prompt_dir
prompt_git
+ prompt_bzr
prompt_hg
prompt_end
}