1
0
Fork 0
mirror of synced 2024-11-26 17:25:35 -05:00

[prompt] eriner: Add help, preview, parameters

and refactor code, inlining auxiliary functions inside
`prompt_eriner_main`.

Theme colors are now customizable with parameters. Also, it works better
with light backgrounds by using `%Sstandout%s` for the segments which
were originally using black as foreground color (intended for dark
backgrounds).

The help explains the parameters, and the preview shows one color
variation.

Fixes #169. Closes #226.
This commit is contained in:
Eric Nielsen 2017-11-29 09:07:53 -05:00 committed by GitHub
parent bc742f0023
commit 39e961117d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,12 +1,11 @@
# vim:ts=2 sw=2 sts=2 ft=zsh # vim:et sts=2 sw=2 ft=zsh
# #
# Eriner's Theme - fork of agnoster # Eriner's Theme - fork of agnoster
# A Powerline-inspired theme for ZSH # A Powerline-inspired theme for ZSH
# #
# In order for this theme to render correctly, you will need a font with # In order for this theme to render correctly, a font with Powerline symbols is
# powerline symbols. A simple way to add the powerline symbols is to follow the # required. A simple way to install a font with Powerline symbols is to follow
# instructions here: # the instructions here: https://github.com/powerline/fonts#installation
# 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 # 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. # prompts, it will only show git information when in a git working directory.
@ -17,6 +16,26 @@
# #
# Requires the `git-info` zmodule to be included in the .zimrc file. # Requires the `git-info` zmodule to be included in the .zimrc file.
prompt_eriner_help () {
cat <<EOH
This prompt is color-scheme-able. You can customize it using:
prompt eriner [<status> [<pwd> [<git_clean> [<git_dirty>]]]]
where the parameters are the background colors for each segment. The default
colors are black, cyan, green, yellow.
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
}
prompt_eriner_main() {
local prompt_eriner_retval=${?}
local prompt_eriner_color1=${1:-black}
local prompt_eriner_color2=${2:-cyan}
### Segment drawing ### Segment drawing
# Utility functions to make it easy and re-usable to draw segmented prompts. # Utility functions to make it easy and re-usable to draw segmented prompts.
@ -25,12 +44,17 @@ local prompt_eriner_bg
# Begin a segment. Takes two arguments, background color and contents of the # Begin a segment. Takes two arguments, background color and contents of the
# new segment. # new segment.
prompt_eriner_segment() { prompt_eriner_segment() {
print -n "%K{$1}" print -n "%K{${1}}"
if [[ -n ${prompt_eriner_bg} ]]; then [[ -n ${prompt_eriner_bg} ]] && print -n "%F{${prompt_eriner_bg}}"
print -n "%F{${prompt_eriner_bg}}" print -n "${2}"
fi prompt_eriner_bg=${1}
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. # End the prompt, closing last segment.
@ -39,28 +63,28 @@ prompt_eriner_end() {
} }
### Prompt components ### Prompt components
# Each component will draw itself, or hide itself if no information needs to be # Each component will draw itself, or hide itself if no information needs to
# shown. # be shown.
# Status: Was there an error? Am I root? Are there background jobs? Ranger # Status: Was there an error? Am I root? Are there background jobs? Ranger
# spawned shell? Who and where am I (user@hostname)? # spawned shell? Who and where am I (user@hostname)?
prompt_eriner_status() { prompt_eriner_status() {
local segment='' local segment=''
(( ${RETVAL} )) && segment+=' %F{red}✘' (( prompt_eriner_retval )) && segment+=' %F{red}✘'
(( ${UID} == 0 )) && segment+=' %F{yellow}⚡' (( UID == 0 )) && segment+=' %F{yellow}⚡'
(( $(jobs -l | wc -l) > 0 )) && segment+=' %F{cyan}⚙' (( $(jobs -l | wc -l) )) && segment+=' %F{cyan}⚙'
(( ${RANGER_LEVEL} )) && segment+=' %F{cyan}r' (( RANGER_LEVEL )) && segment+=' %F{cyan}r'
if [[ ${USER} != ${DEFAULT_USER} || -n ${SSH_CLIENT} ]]; then if [[ ${USER} != ${DEFAULT_USER} || -n ${SSH_CLIENT} ]]; then
segment+=' %F{%(!.yellow.default)}${USER}@%m' segment+=' %F{%(!.yellow.default)}${USER}@%m'
fi fi
if [[ -n ${segment} ]]; then if [[ -n ${segment} ]]; then
prompt_eriner_segment black "${segment} " prompt_eriner_segment ${prompt_eriner_color1} "${segment} "
fi fi
} }
# Pwd: current working directory. # Pwd: current working directory.
prompt_eriner_pwd() { prompt_eriner_pwd() {
prompt_eriner_segment cyan " %F{black}$(short_pwd) " prompt_eriner_standout_segment ${prompt_eriner_color2} " $(short_pwd) "
} }
# Git: branch/detached head, dirty status. # Git: branch/detached head, dirty status.
@ -68,13 +92,10 @@ prompt_eriner_git() {
if [[ -n ${git_info} ]]; then if [[ -n ${git_info} ]]; then
local indicator local indicator
[[ ${git_info[color]} == yellow ]] && indicator='± ' [[ ${git_info[color]} == yellow ]] && indicator='± '
prompt_eriner_segment ${git_info[color]} ' %F{black}${(e)git_info[prompt]} ${indicator}' prompt_eriner_standout_segment ${git_info[color]} " \${(e)git_info[prompt]} ${indicator}"
fi fi
} }
### Main prompt
prompt_eriner_main() {
RETVAL=$?
prompt_eriner_status prompt_eriner_status
prompt_eriner_pwd prompt_eriner_pwd
prompt_eriner_git prompt_eriner_git
@ -93,17 +114,30 @@ prompt_eriner_setup() {
add-zsh-hook precmd prompt_eriner_precmd add-zsh-hook precmd prompt_eriner_precmd
local prompt_eriner_color3=${3:-green}
local prompt_eriner_color4=${4:-yellow}
zstyle ':zim:git-info:branch' format ' %b' zstyle ':zim:git-info:branch' format ' %b'
zstyle ':zim:git-info:commit' format '➦ %c' zstyle ':zim:git-info:commit' format '➦ %c'
zstyle ':zim:git-info:action' format ' (%s)' zstyle ':zim:git-info:action' format ' (%s)'
zstyle ':zim:git-info:clean' format 'green' zstyle ':zim:git-info:clean' format ${prompt_eriner_color3}
zstyle ':zim:git-info:dirty' format 'yellow' zstyle ':zim:git-info:dirty' format ${prompt_eriner_color4}
zstyle ':zim:git-info:keys' format \ zstyle ':zim:git-info:keys' format \
'prompt' '%b%c%s' \ 'prompt' '%b%c%s' \
'color' '%C%D' 'color' '%C%D'
PROMPT='${(e)$(prompt_eriner_main)}' PROMPT="\${(e)\$(prompt_eriner_main ${@:1:2})}"
RPROMPT='' RPROMPT=''
} }
prompt_eriner_setup "$@" prompt_eriner_preview () {
if (( $# )); then
prompt_preview_theme eriner "${@}"
else
prompt_preview_theme eriner
print
prompt_preview_theme eriner black blue green yellow
fi
}
prompt_eriner_setup "${@}"