1
0
mirror of https://github.com/dcarrillo/prezto.git synced 2024-12-24 02:36:48 +00:00
prezto/modules/prompt/functions/prompt_borra_setup

224 lines
6.1 KiB
Plaintext
Raw Permalink Normal View History

2012-10-03 23:00:24 +00:00
#
# A two line customizable theme (colored in blue and white by default).
2012-10-02 20:13:22 +00:00
#
# Author:
2012-10-03 23:00:24 +00:00
# shura <shura1991@gmail.com>
2012-10-02 20:13:22 +00:00
#
# Features:
# - Two lines.
2012-10-03 23:00:24 +00:00
# - VCS integration.
# - Customizable.
2012-10-02 20:13:22 +00:00
#
# Settings (:prezto:module:prompt:theme:borra):
# - plugins: list of plugins (array)
# - prefix: right-side of plugin wrapper (string)
# - separator: plugin separator (string)
# - suffix: left-side of plugin wrapper (string)
# - top: beginning of first line (string)
# - bottom: beginning of second line (string)
# - prompt: right-side of second line (string)
# - rprompt: right prompt enable or disable (bool)
#
# Plugins settings (:prezto:module:prompt:theme:borra:plugin:$plugin):
2012-10-03 23:00:24 +00:00
# Version Control Systems:
2012-10-02 20:13:22 +00:00
# - enable: vcs enable backends (array)
# - format: vcs backends format (string):
2012-10-03 23:00:24 +00:00
# * %b: backend name (to write a bold-end, escape it using %%b)
# * %i: formatted text according to zstyle ':vcs_info:*' formats (or actionformats)
# User and Host:
2012-10-02 20:13:22 +00:00
# - format: username and hostname format (string):
2012-10-03 23:00:24 +00:00
# * %u: username
# * %h: hostname
2012-10-02 20:13:22 +00:00
# Example:
# zstyle ':prezto:module:prompt:theme:borra' separator ' '
#
# Screenshots:
# http://i.imgur.com/rEgWv.png
# http://ascii.io/a/1310
2012-10-03 23:00:24 +00:00
#
2012-10-02 20:13:22 +00:00
2012-10-03 23:00:24 +00:00
function +borra-pts {
print -n '/dev/%y'
2012-10-02 20:13:22 +00:00
}
2012-10-03 23:00:24 +00:00
function +borra-rvm-info {
if (( ! $+functions[rvm] )); then
return 1
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
2012-10-02 20:13:22 +00:00
vcs_info # need VCS_INFO_backends
2012-10-03 23:00:24 +00:00
zstyle -a ':prezto:module:prompt:theme:borra:plugin:vcs' enable 'enabled'
zstyle -s ':prezto:module:prompt:theme:borra:plugin:vcs' format 'format'
2012-10-02 20:13:22 +00:00
2012-10-03 23:00:24 +00:00
for backend in ${VCS_INFO_backends[@]}; do
if (( $+enabled[$backend] )); then
continue
fi
2012-10-02 20:13:22 +00:00
2012-10-03 23:00:24 +00:00
zstyle ':vcs_info:*' enable "$backend"
vcs_info || continue
if [[ -z "${vcs_info_msg_0_}" ]]; then
continue
fi
zformat -f s "$format" "b:$backend" "i:$vcs_info_msg_0_"
2012-10-02 20:13:22 +00:00
2012-10-03 23:00:24 +00:00
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
2012-10-02 20:13:22 +00:00
}
2012-10-03 23:00:24 +00:00
function +vi-git-status-untracked {
if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
hook_com[unstaged]=' %F{red}⚑%f'
2012-10-02 20:13:22 +00:00
fi
}
2012-10-03 23:00:24 +00:00
function prompt_borra_set_zstyle_if_not_set {
zstyle -T "$1" "$2" && zstyle "$@"
}
2012-10-02 20:13:22 +00:00
function prompt_borra_wrap_plugin {
local prefix
local suffix
zstyle -s ':prezto:module:prompt:theme:borra' prefix 'prefix'
zstyle -s ':prezto:module:prompt:theme:borra' suffix 'suffix'
2012-10-03 23:00:24 +00:00
print -n -- "${2}${prefix}${1}${suffix}"
2012-10-02 20:13:22 +00:00
}
function prompt_borra_render_item {
local res
res="$($1 "$2" 2>/dev/null)"
case "$?" in
2012-10-03 23:00:24 +00:00
(0)
prompt_borra_wrap_plugin "$res" "$2"
;;
(23)
print -n "$res"
;;
(*)
return 1
;;
2012-10-02 20:13:22 +00:00
esac
}
function prompt_borra_render_plugins {
local res=""
local plugin
2012-10-03 23:00:24 +00:00
local -a plugins
2012-10-02 20:13:22 +00:00
local sep
zstyle -a ':prezto:module:prompt:theme:borra' plugins 'plugins'
2012-10-03 23:00:24 +00:00
for plugin in "$plugins[@]"; do
2012-10-02 20:13:22 +00:00
res+="$(prompt_borra_render_item "+borra-$plugin" "$sep")"
2012-10-03 23:00:24 +00:00
if [[ -z "$sep" && ! -z "$res" ]]; then
zstyle -s ':prezto:module:prompt:theme:borra' separator 'sep'
fi
2012-10-02 20:13:22 +00:00
done
2012-10-03 23:00:24 +00:00
print -n "$res"
2012-10-02 20:13:22 +00:00
}
function prompt_borra_create_prompt {
local plugins="$(prompt_borra_render_plugins)"
local res=""
local top
local bottom
local prompt
2012-10-03 23:00:24 +00:00
if [[ ! -z "$plugins" ]]; then
2012-10-02 20:13:22 +00:00
zstyle -s ':prezto:module:prompt:theme:borra' top 'top'
zstyle -s ':prezto:module:prompt:theme:borra' bottom 'bottom'
2012-10-03 23:00:24 +00:00
res="
${top}${plugins}
2012-10-02 20:13:22 +00:00
${bottom}"
2012-10-03 23:00:24 +00:00
2012-10-02 20:13:22 +00:00
fi
2012-10-03 23:00:24 +00:00
2012-10-02 20:13:22 +00:00
zstyle -s ':prezto:module:prompt:theme:borra' prompt 'prompt'
print -n "${res}${prompt}"
}
2012-10-03 23:00:24 +00:00
function prompt_borra_precmd {
local rprompt
PROMPT="$(prompt_borra_create_prompt)"
zstyle -b ':prezto:module:prompt:theme:borra' rprompt 'rprompt'
if [[ "$rprompt" = yes ]]; then
RPROMPT='%(?..%F{red}%? ↵%f)'
else
RPROMPT=''
2012-10-02 20:13:22 +00:00
fi
}
2012-10-03 23:00:24 +00:00
function prompt_borra_setup {
setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS
prompt_opts=(cr percent subst)
2012-10-02 20:13:22 +00:00
2012-10-03 23:00:24 +00:00
# Load required functions.
autoload -Uz add-zsh-hook
autoload -Uz vcs_info
2012-10-02 20:13:22 +00:00
2012-10-03 23:00:24 +00:00
# Add hook for calling git-info before each command.
add-zsh-hook precmd prompt_borra_precmd
2012-10-02 20:13:22 +00:00
2012-10-03 23:00:24 +00:00
# Call vcs_info to populate $VCS_INFO_backends.
vcs_info
2012-10-02 20:13:22 +00:00
2012-10-03 23:00:24 +00:00
prompt_borra_set_zstyle_if_not_set ':prezto:module:prompt:theme:borra' plugins 'userhost' 'pts' 'rvm-info' 'vcs-info'
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'
2012-10-02 20:13:22 +00:00
2012-10-03 23:00:24 +00:00
# Set vcs_info parameters.
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'
2012-10-02 20:13:22 +00:00
}
prompt_borra_setup "$@"