|
# vim:ft=zsh ts=2 sw=2 sts=2 |
|
# |
|
# agnoster's Theme - tkw1536 fork - https://gist.github.com/tkw1536/9f86f8ca50d421018fb5 |
|
# A Powerline-inspired theme for ZSH |
|
# |
|
# See README.md for details |
|
|
|
### Colors Config |
|
CURRENT_BG='NONE' # Background color |
|
PRIMARY_FG=black # Foreground color |
|
|
|
### Symbols Config |
|
# Segements + Arrows |
|
SEGMENT_SEPARATOR="\u00BB" # Seperates segments |
|
RARROW=">" # At the end for the actual prompt |
|
|
|
# Git status |
|
PLUSMINUS="\u00B1" # We have files to add or remove |
|
BRANCH="|" # On a branch |
|
DETACHED="\u00A6" # in detached status |
|
|
|
# Session Status |
|
LIGHTNING="\u26a1" # You are root |
|
GEAR="\u2699" # Some jobs are active |
|
|
|
# Symbols for command return status |
|
CHECKMARK="\u2713" # Command == 0 |
|
CROSS="\u2718" #Command != 0 |
|
|
|
### Helper functions |
|
|
|
# Month name: Get the current month name. |
|
# Always in the english locale |
|
month_name() { |
|
month=$(date +"%m") |
|
months=(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) |
|
echo ${months[$month]} |
|
} |
|
|
|
### The segments |
|
|
|
# Begin a segment |
|
# Takes two arguments, background and foreground. Both can be omitted, |
|
# rendering default background/foreground. |
|
prompt_segment() { |
|
local bg fg |
|
[[ -n $1 ]] && bg="%K{$1}" || bg="%k" |
|
[[ -n $2 ]] && fg="%F{$2}" || fg="%f" |
|
if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then |
|
print -n "%{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%}" |
|
else |
|
print -n "%{$bg%}%{$fg%}" |
|
fi |
|
CURRENT_BG=$1 |
|
[[ -n $3 ]] && print -n $3 |
|
} |
|
|
|
# End the prompt, closing any open segments and printing the new line |
|
prompt_end() { |
|
if [[ -n $CURRENT_BG ]]; then |
|
print -n "%{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR" |
|
else |
|
print -n "%{%k%}" |
|
fi |
|
print -n "%{%f%}" |
|
CURRENT_BG='' |
|
print -n "%{%F{green}%}[%D{%d $(month_name) %Y %H:%M:%S}]%{%f%b%k%}" |
|
print -n "\n$RARROW " |
|
} |
|
|
|
### Prompt components |
|
# Each component will draw itself, and hide itself if no information needs to be shown |
|
|
|
# Context: user@hostname (who am I and where am I) |
|
prompt_context() { |
|
local user=`whoami` |
|
|
|
if [[ "$user" != "$DEFAULT_USER" || -n "$SSH_CONNECTION" ]]; then |
|
prompt_segment $PRIMARY_FG default " %(!.%{%F{yellow}%}.)$user@%m " |
|
fi |
|
} |
|
|
|
# Git: branch/detached head, dirty status |
|
prompt_git() { |
|
local color ref |
|
is_dirty() { |
|
test -n "$(git status --porcelain --ignore-submodules 2> /dev/null)" |
|
} |
|
ref="$vcs_info_msg_0_" |
|
if [[ -n "$ref" ]]; then |
|
if is_dirty; then |
|
color=yellow |
|
ref="${ref} $PLUSMINUS" |
|
else |
|
color=green |
|
ref="${ref} " |
|
fi |
|
if [[ "${ref/.../}" == "$ref" ]]; then |
|
ref="$BRANCH $ref" |
|
else |
|
ref="$DETACHED ${ref/.../}" |
|
fi |
|
prompt_segment $color $PRIMARY_FG |
|
print -Pn " $ref" |
|
fi |
|
} |
|
|
|
# Dir: current working directory |
|
prompt_dir() { |
|
prompt_segment blue $PRIMARY_FG ' %~ ' |
|
} |
|
|
|
# Status: |
|
# - was there an error |
|
# - am I root |
|
# - are there background jobs? |
|
prompt_status() { |
|
local symbols |
|
symbols=() |
|
[[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}$CROSS" |
|
[[ $RETVAL -eq 0 ]] && symbols+="%{%F{green}%}$CHECKMARK" |
|
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}$LIGHTNING" |
|
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}$GEAR" |
|
|
|
[[ -n "$symbols" ]] && prompt_segment $PRIMARY_FG default " $symbols " |
|
} |
|
|
|
### Main prompt |
|
prompt_agnoster_main() { |
|
RETVAL=$? |
|
CURRENT_BG='NONE' |
|
prompt_status |
|
prompt_context |
|
prompt_dir |
|
prompt_git |
|
prompt_end |
|
} |
|
|
|
prompt_agnoster_precmd() { |
|
vcs_info |
|
PROMPT='%{%f%b%k%}$(prompt_agnoster_main)' |
|
} |
|
|
|
prompt_agnoster_setup() { |
|
autoload -Uz add-zsh-hook |
|
autoload -Uz vcs_info |
|
|
|
prompt_opts=(cr subst percent) |
|
|
|
add-zsh-hook precmd prompt_agnoster_precmd |
|
|
|
zstyle ':vcs_info:*' enable git |
|
zstyle ':vcs_info:*' check-for-changes false |
|
zstyle ':vcs_info:git*' formats '%b' |
|
zstyle ':vcs_info:git*' actionformats '%b (%a)' |
|
} |
|
|
|
prompt_agnoster_setup "$@" |