1
0
Fork 0
mirror of synced 2024-07-27 18:41:12 -04:00
zimfw/modules/prompt/themes/eriner.zsh-theme
Eric Nielsen a7c98adb4a Rewrite eriner theme using the Zim git-info module
Based on my rewrite of the Agnoster theme, uses simpler segment drawing
functions and only relies on local variables. Uses git-info module in
non-verbose mode, so a repo with only untracked files will not count as
dirty (but dirty state is computed faster). Also took the freedom of
adding an extra space character after the 'r' for the Ranger segment,
and after the dirty indicator for the Git segment. Everything else looks
and behaves exactly the same as the original prompt.
2017-03-02 07:47:26 -05:00

110 lines
3.1 KiB
Bash

# vim:ts=2 sw=2 sts=2 ft=zsh
#
# Eriner's Theme - fork of agnoster
# A Powerline-inspired theme for ZSH
#
# In order for this theme to render correctly, you will need a font with
# powerline symbols. A simple way to add the powerline symbols is to follow the
# instructions here:
# https://simplyian.com/2014/03/28/using-powerline-symbols-with-your-current-font/
#
# The aim of this theme is to only show you *relevant* information. Like most
# prompts, it will only show git information when in a git working directory.
# However, it goes a step further: everything from the current user and
# hostname to whether the last call exited with an error to whether background
# jobs are running in this shell will all be displayed automatically when
# appropriate.
#
# Uses the 'git-info' Zim module.
### Segment drawing
# Utility functions to make it easy and re-usable to draw segmented prompts.
local prompt_eriner_bg
# Begin a segment. Takes two arguments, background color and contents of the
# new segment.
prompt_eriner_segment() {
print -n "%K{$1}"
if [[ -n ${prompt_eriner_bg} ]]; then
print -n "%F{${prompt_eriner_bg}}"
fi
print -n "$2"
prompt_eriner_bg=$1
}
# End the prompt, closing last segment.
prompt_eriner_end() {
print -n "%k%F{${prompt_eriner_bg}}%f "
}
### Prompt components
# Each component will draw itself, or hide itself if no information needs to be
# shown.
# Status: Was there an error? Am I root? Are there background jobs? Ranger
# spawned shell? Who and where am I (user@hostname)?
prompt_eriner_status() {
local segment=''
(( ${RETVAL} )) && segment+=' %F{red}✘'
(( ${UID} == 0 )) && segment+=' %F{yellow}⚡'
(( $(jobs -l | wc -l) > 0 )) && segment+=' %F{cyan}⚙'
(( ${RANGER_LEVEL} )) && segment+=' %F{cyan}r'
if [[ ${USER} != ${DEFAULT_USER} || -n ${SSH_CLIENT} ]]; then
segment+=' %F{%(!.yellow.default)}${USER}@%m'
fi
if [[ -n ${segment} ]]; then
prompt_eriner_segment black "${segment} "
fi
}
# Pwd: current working directory.
prompt_eriner_pwd() {
prompt_eriner_segment cyan " %F{black}$(short_pwd) "
}
# Git: branch/detached head, dirty status.
prompt_eriner_git() {
if [[ -n ${git_info} ]]; then
local indicator
[[ ${git_info[color]} == yellow ]] && indicator='± '
prompt_eriner_segment ${git_info[color]} " %F{black}${(e)git_info[prompt]} ${indicator}"
fi
}
### Main prompt
prompt_eriner_main() {
RETVAL=$?
prompt_eriner_status
prompt_eriner_pwd
prompt_eriner_git
prompt_eriner_end
}
prompt_eriner_precmd() {
[[ ${+functions[git-info]} ]] && git-info
}
prompt_eriner_setup() {
autoload -Uz colors && colors
autoload -Uz add-zsh-hook
prompt_opts=(cr percent subst)
add-zsh-hook precmd prompt_eriner_precmd
zstyle ':zim:git-info:branch' format ' %b'
zstyle ':zim:git-info:commit' format '➦ %c'
zstyle ':zim:git-info:action' format ' (%s)'
zstyle ':zim:git-info:clean' format 'green'
zstyle ':zim:git-info:dirty' format 'yellow'
zstyle ':zim:git-info:keys' format \
'prompt' '%b%c%s' \
'color' '%C%D'
PROMPT='${(e)$(prompt_eriner_main)}'
RPROMPT=''
}
prompt_eriner_setup "$@"