1
0
Fork 0

Clean up the borra theme

issue/306-default-zstyle-function
Sorin Ionescu 12 years ago
parent 3456166ab0
commit 59f448d6ed

@ -1,14 +1,13 @@
# vim:syn=zsh #
# A two line pluggable and themable theme (blue/white default). # A two line customizable theme (colored in blue and white by default).
# #
# Author: # Author:
# shura <shura1991@gmail.com> # shura <shura1991@gmail.com>
# #
# Features: # Features:
# - Two lines. # - Two lines.
# - All the VCS informations (default). # - VCS integration.
# - Pluggable. # - Customizable.
# - Themable.
# #
# Settings (:prezto:module:prompt:theme:borra): # Settings (:prezto:module:prompt:theme:borra):
# - plugins: list of plugins (array) # - plugins: list of plugins (array)
@ -21,69 +20,93 @@
# - rprompt: right prompt enable or disable (bool) # - rprompt: right prompt enable or disable (bool)
# #
# Plugins settings (:prezto:module:prompt:theme:borra:plugin:$plugin): # Plugins settings (:prezto:module:prompt:theme:borra:plugin:$plugin):
# vcs: # Version Control Systems:
# - enable: vcs enable backends (array) # - enable: vcs enable backends (array)
# - format: vcs backends format (string): # - format: vcs backends format (string):
# - %b: backend name (to write a bold-end, escape it using %%b) # * %b: backend name (to write a bold-end, escape it using %%b)
# - %i: formatted text according to zstyle ':vcs_info:*' formats (or actionformats) # * %i: formatted text according to zstyle ':vcs_info:*' formats (or actionformats)
# userhost # User and Host:
# - format: username and hostname format (string): # - format: username and hostname format (string):
# - %u: username # * %u: username
# - %h: hostname # * %h: hostname
# Example: # Example:
# zstyle ':prezto:module:prompt:theme:borra' separator ' ' # zstyle ':prezto:module:prompt:theme:borra' separator ' '
# #
# Screenshots: # Screenshots:
# http://i.imgur.com/rEgWv.png # http://i.imgur.com/rEgWv.png
# ascii.io presentation:
# http://ascii.io/a/1310 # http://ascii.io/a/1310
# borra prompt theme #
function prompt_borra_set_zstyle_if_not_set { function +borra-pts {
zstyle -T "$1" "$2" && zstyle "$@" print -n '/dev/%y'
} }
function prompt_borra_setup { function +borra-rvm-info {
autoload -Uz add-zsh-hook if (( ! $+functions[rvm] )); then
autoload -Uz vcs_info return 1
prompt_opts=(cr percent subst) fi
local rb="$(rvm-prompt s)"
if [[ -z "${rb}" ]]; then
print "$(rvm-prompt i v p r)" || print "${rb}"
fi
}
function +borra-userhost {
local format
local res
zstyle -s ':prezto:module:prompt:theme:borra:plugin:userhost' format 'format'
zformat -f res "$format" u:'%(!.%SROOT%s.%n)' h:'%m'
print -n "$res"
}
function +borra-vcs-info {
local res=""
local sep="$1"
local backend
local enabled
local format
local s
add-zsh-hook precmd prompt_borra_precmd
vcs_info # need VCS_INFO_backends vcs_info # need VCS_INFO_backends
zstyle -a ':prezto:module:prompt:theme:borra:plugin:vcs' enable 'enabled'
zstyle -s ':prezto:module:prompt:theme:borra:plugin:vcs' format 'format'
prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra' plugins 'userhost' 'pts' 'rvm-info' 'vcs-info' for backend in ${VCS_INFO_backends[@]}; do
prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra' prefix '%F{blue}(%f' if (( $+enabled[$backend] )); then
prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra' separator '%F{blue}-%f' continue
prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra' suffix '%F{blue}%)%f' fi
prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra' top '%F{blue}╭-%f'
prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra' bottom '%F{blue}╰─%f'
prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra' prompt '%F{blue}(%f%B%$((COLUMNS / 2))<...<%~%<<%b%F{blue})%F{yellow}>%f '
prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra' rprompt 'yes'
prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra:plugin:vcs' enable ${VCS_INFO_backends[@]}
prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra:plugin:vcs' format '%b: %i'
prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra:plugin:userhost' format '%u%F{blue}@%f%h'
zstyle ':vcs_info:*' check-for-changes 'true' zstyle ':vcs_info:*' enable "$backend"
zstyle ':vcs_info:*' unstagedstr ' %F{yellow}⚑%f' vcs_info || continue
zstyle ':vcs_info:*' stagedstr ' %F{green}⚑%f'
zstyle ':vcs_info:*' actionformats '%b%u%c [%a]' if [[ -z "${vcs_info_msg_0_}" ]]; then
zstyle ':vcs_info:*' formats '%b%u%c' continue
zstyle ':vcs_info:*+set-message:*' hooks 'git-st' fi
zformat -f s "$format" "b:$backend" "i:$vcs_info_msg_0_"
prompt_borra_precmd res+="$(prompt_borra_wrap_plugin "$s" "$sep")"
if [[ -z "$sep" && ! -z "$res" ]]; then
zstyle -s ':prezto:module:prompt:theme:borra' separator 'sep'
fi
done
print -n -- "$res"
return 23
} }
function prompt_borra_precmd { function +vi-git-status-untracked {
local rprompt if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
PROMPT="$(prompt_borra_create_prompt)" hook_com[unstaged]=' %F{red}⚑%f'
zstyle -b ':prezto:module:prompt:theme:borra' rprompt 'rprompt'
if [ "$rprompt" = yes ]; then
RPROMPT='%(?..%F{red}%? ↵%f)'
else
RPROMPT=''
fi fi
} }
function prompt_borra_set_zstyle_if_not_set {
zstyle -T "$1" "$2" && zstyle "$@"
}
function prompt_borra_wrap_plugin { function prompt_borra_wrap_plugin {
local prefix local prefix
local suffix local suffix
@ -91,7 +114,7 @@ function prompt_borra_wrap_plugin {
zstyle -s ':prezto:module:prompt:theme:borra' prefix 'prefix' zstyle -s ':prezto:module:prompt:theme:borra' prefix 'prefix'
zstyle -s ':prezto:module:prompt:theme:borra' suffix 'suffix' zstyle -s ':prezto:module:prompt:theme:borra' suffix 'suffix'
print -n -- "$2$prefix$1$suffix" print -n -- "${2}${prefix}${1}${suffix}"
} }
function prompt_borra_render_item { function prompt_borra_render_item {
@ -99,27 +122,34 @@ function prompt_borra_render_item {
res="$($1 "$2" 2>/dev/null)" res="$($1 "$2" 2>/dev/null)"
case "$?" in case "$?" in
0) prompt_borra_wrap_plugin "$res" "$2" ;; (0)
23) print -n "$res" ;; prompt_borra_wrap_plugin "$res" "$2"
*) return 1 ;; ;;
(23)
print -n "$res"
;;
(*)
return 1
;;
esac esac
} }
function prompt_borra_render_plugins { function prompt_borra_render_plugins {
local res="" local res=""
local plugin local plugin
local plugins local -a plugins
local sep local sep
zstyle -a ':prezto:module:prompt:theme:borra' plugins 'plugins' zstyle -a ':prezto:module:prompt:theme:borra' plugins 'plugins'
for plugin in ${plugins[*]} for plugin in "$plugins[@]"; do
do
res+="$(prompt_borra_render_item "+borra-$plugin" "$sep")" res+="$(prompt_borra_render_item "+borra-$plugin" "$sep")"
[ -z "$sep" -a ! -z "$res" ] && zstyle -s ':prezto:module:prompt:theme:borra' separator 'sep' if [[ -z "$sep" && ! -z "$res" ]]; then
zstyle -s ':prezto:module:prompt:theme:borra' separator 'sep'
fi
done done
print -n "${res}" print -n "$res"
} }
function prompt_borra_create_prompt { function prompt_borra_create_prompt {
@ -129,68 +159,65 @@ function prompt_borra_create_prompt {
local bottom local bottom
local prompt local prompt
if [ ! -z "$plugins" ] if [[ ! -z "$plugins" ]]; then
then
zstyle -s ':prezto:module:prompt:theme:borra' top 'top' zstyle -s ':prezto:module:prompt:theme:borra' top 'top'
zstyle -s ':prezto:module:prompt:theme:borra' bottom 'bottom' zstyle -s ':prezto:module:prompt:theme:borra' bottom 'bottom'
res="${top}${plugins}
res="
${top}${plugins}
${bottom}" ${bottom}"
fi fi
zstyle -s ':prezto:module:prompt:theme:borra' prompt 'prompt' zstyle -s ':prezto:module:prompt:theme:borra' prompt 'prompt'
print -n "${res}${prompt}" print -n "${res}${prompt}"
} }
function +borra-userhost { function prompt_borra_precmd {
local fmt local rprompt
local res PROMPT="$(prompt_borra_create_prompt)"
zstyle -s ':prezto:module:prompt:theme:borra:plugin:userhost' format 'fmt' zstyle -b ':prezto:module:prompt:theme:borra' rprompt 'rprompt'
zformat -f res "$fmt" u:'%(!.%SROOT%s.%n)' h:'%m' if [[ "$rprompt" = yes ]]; then
print -n "$res" RPROMPT='%(?..%F{red}%? ↵%f)'
} else
RPROMPT=''
function +borra-pts {
print -n '/dev/%y'
}
function +borra-rvm-info {
(( $+functions[rvm] )) || return 1
local rb="$(rvm-prompt s)"
[ -z "${rb}" ] && echo "$(rvm-prompt i v p r)" || echo "${rb}"
}
function +vi-git-st {
if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
hook_com[unstaged]=' %F{red}⚑%f'
fi fi
} }
function +borra-vcs-info { function prompt_borra_setup {
local res="" setopt LOCAL_OPTIONS
local sep="$1" unsetopt XTRACE KSH_ARRAYS
local backend prompt_opts=(cr percent subst)
local enabled
local fmt
local s
vcs_info # need VCS_INFO_backends
zstyle -a ':prezto:module:prompt:theme:borra:plugin:vcs' enable 'enabled'
zstyle -s ':prezto:module:prompt:theme:borra:plugin:vcs' format 'fmt'
for backend in ${VCS_INFO_backends[@]}; do # Load required functions.
[ "${enabled[(I)$backend]}" = 0 ] && continue autoload -Uz add-zsh-hook
zstyle ':vcs_info:*' enable "$backend" autoload -Uz vcs_info
vcs_info || continue
[ -z "${vcs_info_msg_0_}" ] && continue
zformat -f s "$fmt" b:"$backend" i:"$vcs_info_msg_0_" # Add hook for calling git-info before each command.
add-zsh-hook precmd prompt_borra_precmd
res+="$(prompt_borra_wrap_plugin "$s" "$sep")" # Call vcs_info to populate $VCS_INFO_backends.
vcs_info
[ -z "$sep" -a ! -z "$res" ] && zstyle -s ':prezto:module:prompt:theme:borra' separator 'sep' prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra' plugins 'userhost' 'pts' 'rvm-info' 'vcs-info'
done prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra' prefix '%F{blue}(%f'
prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra' separator '%F{blue}-%f'
prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra' suffix '%F{blue}%)%f'
prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra' top '%F{blue}╭-%f'
prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra' bottom '%F{blue}╰─%f'
prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra' prompt '%F{blue}(%f%B%$((COLUMNS / 2))<...<%~%<<%b%F{blue})%F{yellow}>%f '
prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra' rprompt 'yes'
prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra:plugin:vcs' enable "$VCS_INFO_backends[@]"
prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra:plugin:vcs' format '%b: %i'
prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra:plugin:userhost' format '%u%F{blue}@%f%h'
print -n -- "$res" # Set vcs_info parameters.
return 23 zstyle ':vcs_info:*' check-for-changes 'true'
zstyle ':vcs_info:*' unstagedstr ' %F{yellow}⚑%f'
zstyle ':vcs_info:*' stagedstr ' %F{green}⚑%f'
zstyle ':vcs_info:*' actionformats '%b%u%c [%a]'
zstyle ':vcs_info:*' formats '%b%u%c'
zstyle ':vcs_info:*+set-message:*' hooks 'git-status-untracked'
} }
prompt_borra_setup "$@" prompt_borra_setup "$@"

Loading…
Cancel
Save