2017-11-29 09:07:53 -05:00
|
|
|
# vim:et sts=2 sw=2 ft=zsh
|
2017-03-01 15:18:16 -05:00
|
|
|
#
|
2015-12-15 19:21:06 -05:00
|
|
|
# Eriner's Theme - fork of agnoster
|
2015-12-15 00:12:17 -05:00
|
|
|
# A Powerline-inspired theme for ZSH
|
|
|
|
#
|
2017-11-29 09:07:53 -05:00
|
|
|
# In order for this theme to render correctly, a font with Powerline symbols is
|
|
|
|
# required. A simple way to install a font with Powerline symbols is to follow
|
|
|
|
# the instructions here: https://github.com/powerline/fonts#installation
|
2015-12-15 00:12:17 -05:00
|
|
|
#
|
|
|
|
# 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.
|
2017-03-01 15:18:16 -05:00
|
|
|
#
|
2017-03-02 09:56:38 -05:00
|
|
|
# Requires the `git-info` zmodule to be included in the .zimrc file.
|
2015-12-15 00:12:17 -05:00
|
|
|
|
2017-11-29 09:07:53 -05:00
|
|
|
prompt_eriner_help () {
|
|
|
|
cat <<EOH
|
|
|
|
This prompt is color-scheme-able. You can customize it using:
|
2015-12-15 00:12:17 -05:00
|
|
|
|
2018-01-08 12:22:35 -05:00
|
|
|
prompt eriner [status_color] [pwd_color] [git_clean_color] [git_dirty_color]
|
2015-12-15 00:12:17 -05:00
|
|
|
|
2017-11-29 09:07:53 -05:00
|
|
|
where the parameters are the background colors for each segment. The default
|
2018-01-08 12:22:35 -05:00
|
|
|
values are black, cyan, green, and yellow.
|
2015-12-15 00:12:17 -05:00
|
|
|
|
2017-11-29 09:07:53 -05:00
|
|
|
In order for this prompt to render correctly, a font with Powerline symbols is
|
|
|
|
required. A simple way to install a font with Powerline symbols is to follow
|
|
|
|
the instructions here: https://github.com/powerline/fonts#installation
|
|
|
|
EOH
|
2015-12-15 00:12:17 -05:00
|
|
|
}
|
|
|
|
|
2015-12-15 21:51:28 -05:00
|
|
|
prompt_eriner_main() {
|
2017-11-29 09:07:53 -05:00
|
|
|
local prompt_eriner_retval=${?}
|
|
|
|
local prompt_eriner_color1=${1:-black}
|
|
|
|
local prompt_eriner_color2=${2:-cyan}
|
|
|
|
|
|
|
|
### 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}}"
|
|
|
|
[[ -n ${prompt_eriner_bg} ]] && print -n "%F{${prompt_eriner_bg}}"
|
|
|
|
print -n "${2}"
|
|
|
|
prompt_eriner_bg=${1}
|
|
|
|
}
|
|
|
|
|
|
|
|
prompt_eriner_standout_segment() {
|
|
|
|
print -n "%S%F{${1}}"
|
|
|
|
[[ -n ${prompt_eriner_bg} ]] && print -n "%K{${prompt_eriner_bg}}%k"
|
|
|
|
print -n "${2}%s"
|
|
|
|
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=''
|
|
|
|
(( prompt_eriner_retval )) && segment+=' %F{red}✘'
|
|
|
|
(( UID == 0 )) && segment+=' %F{yellow}⚡'
|
|
|
|
(( $(jobs -l | wc -l) )) && 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 ${prompt_eriner_color1} "${segment} "
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Pwd: current working directory.
|
|
|
|
prompt_eriner_pwd() {
|
|
|
|
prompt_eriner_standout_segment ${prompt_eriner_color2} " $(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_standout_segment ${git_info[color]} " \${(e)git_info[prompt]} ${indicator}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-03-01 15:18:16 -05:00
|
|
|
prompt_eriner_status
|
|
|
|
prompt_eriner_pwd
|
|
|
|
prompt_eriner_git
|
|
|
|
prompt_eriner_end
|
2015-12-15 00:12:17 -05:00
|
|
|
}
|
|
|
|
|
2015-12-15 21:51:28 -05:00
|
|
|
prompt_eriner_precmd() {
|
2017-03-02 09:56:38 -05:00
|
|
|
(( ${+functions[git-info]} )) && git-info
|
2015-12-15 00:12:17 -05:00
|
|
|
}
|
|
|
|
|
2015-12-15 21:51:28 -05:00
|
|
|
prompt_eriner_setup() {
|
2018-02-07 18:15:17 -05:00
|
|
|
autoload -Uz add-zsh-hook && add-zsh-hook precmd prompt_eriner_precmd
|
2015-12-15 00:12:17 -05:00
|
|
|
|
2017-10-01 21:35:47 -04:00
|
|
|
prompt_opts=(cr percent sp subst)
|
2015-12-15 00:12:17 -05:00
|
|
|
|
2017-11-29 09:07:53 -05:00
|
|
|
local prompt_eriner_color3=${3:-green}
|
|
|
|
local prompt_eriner_color4=${4:-yellow}
|
|
|
|
|
2017-03-01 15:18:16 -05:00
|
|
|
zstyle ':zim:git-info:branch' format ' %b'
|
|
|
|
zstyle ':zim:git-info:commit' format '➦ %c'
|
|
|
|
zstyle ':zim:git-info:action' format ' (%s)'
|
2017-11-29 09:07:53 -05:00
|
|
|
zstyle ':zim:git-info:clean' format ${prompt_eriner_color3}
|
|
|
|
zstyle ':zim:git-info:dirty' format ${prompt_eriner_color4}
|
2017-03-01 15:18:16 -05:00
|
|
|
zstyle ':zim:git-info:keys' format \
|
|
|
|
'prompt' '%b%c%s' \
|
|
|
|
'color' '%C%D'
|
|
|
|
|
2018-01-08 12:22:35 -05:00
|
|
|
PS1="\${(e)\$(prompt_eriner_main ${@:1:2})}"
|
|
|
|
RPS1=''
|
2015-12-15 00:12:17 -05:00
|
|
|
}
|
|
|
|
|
2017-11-29 09:07:53 -05:00
|
|
|
prompt_eriner_preview () {
|
2018-02-07 18:15:17 -05:00
|
|
|
if (( ${#} )); then
|
2017-11-29 09:07:53 -05:00
|
|
|
prompt_preview_theme eriner "${@}"
|
|
|
|
else
|
|
|
|
prompt_preview_theme eriner
|
|
|
|
print
|
|
|
|
prompt_preview_theme eriner black blue green yellow
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
prompt_eriner_setup "${@}"
|