2017-03-01 15:18:16 -05:00
|
|
|
# vim:ts=2 sw=2 sts=2 ft=zsh
|
|
|
|
#
|
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-03-01 15:18:16 -05:00
|
|
|
# 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:
|
2015-12-29 11:19:36 -05:00
|
|
|
# https://simplyian.com/2014/03/28/using-powerline-symbols-with-your-current-font/
|
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
|
|
|
|
|
|
|
### Segment drawing
|
2017-03-01 15:18:16 -05:00
|
|
|
# Utility functions to make it easy and re-usable to draw segmented prompts.
|
2015-12-15 00:12:17 -05:00
|
|
|
|
2017-03-01 15:18:16 -05:00
|
|
|
local prompt_eriner_bg
|
2015-12-15 00:12:17 -05:00
|
|
|
|
2017-03-01 15:18:16 -05:00
|
|
|
# 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}}"
|
2015-12-15 00:12:17 -05:00
|
|
|
fi
|
2017-03-01 15:18:16 -05:00
|
|
|
print -n "$2"
|
|
|
|
prompt_eriner_bg=$1
|
2015-12-15 00:12:17 -05:00
|
|
|
}
|
|
|
|
|
2017-03-01 15:18:16 -05:00
|
|
|
# End the prompt, closing last segment.
|
|
|
|
prompt_eriner_end() {
|
|
|
|
print -n "%k%F{${prompt_eriner_bg}}%f "
|
2015-12-15 00:12:17 -05:00
|
|
|
}
|
|
|
|
|
2017-03-01 15:18:16 -05:00
|
|
|
### Prompt components
|
|
|
|
# Each component will draw itself, or hide itself if no information needs to be
|
|
|
|
# shown.
|
|
|
|
|
2017-04-17 17:29:31 -04:00
|
|
|
# Status: Was there an error? Am I root? Are there background jobs? Ranger
|
|
|
|
# spawned shell? Who and where am I (user@hostname)?
|
2017-03-01 15:18:16 -05:00
|
|
|
prompt_eriner_status() {
|
|
|
|
local segment=''
|
|
|
|
(( ${RETVAL} )) && segment+=' %F{red}✘'
|
|
|
|
(( ${UID} == 0 )) && segment+=' %F{yellow}⚡'
|
|
|
|
(( $(jobs -l | wc -l) > 0 )) && segment+=' %F{cyan}⚙'
|
2017-04-17 17:29:31 -04:00
|
|
|
(( ${RANGER_LEVEL} )) && segment+=' %F{cyan}r'
|
2017-03-01 15:18:16 -05:00
|
|
|
if [[ ${USER} != ${DEFAULT_USER} || -n ${SSH_CLIENT} ]]; then
|
|
|
|
segment+=' %F{%(!.yellow.default)}${USER}@%m'
|
2016-07-17 08:53:34 -04:00
|
|
|
fi
|
2017-03-01 15:18:16 -05:00
|
|
|
if [[ -n ${segment} ]]; then
|
|
|
|
prompt_eriner_segment black "${segment} "
|
2015-12-15 00:12:17 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-03-01 15:18:16 -05:00
|
|
|
# Pwd: current working directory.
|
|
|
|
prompt_eriner_pwd() {
|
|
|
|
prompt_eriner_segment cyan " %F{black}$(short_pwd) "
|
2015-12-15 00:12:17 -05:00
|
|
|
}
|
|
|
|
|
2017-03-01 15:18:16 -05:00
|
|
|
# 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
|
2015-12-15 00:12:17 -05:00
|
|
|
}
|
|
|
|
|
2017-03-01 15:18:16 -05:00
|
|
|
### Main prompt
|
2015-12-15 21:51:28 -05:00
|
|
|
prompt_eriner_main() {
|
2015-12-15 00:12:17 -05:00
|
|
|
RETVAL=$?
|
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() {
|
2017-03-01 15:18:16 -05:00
|
|
|
autoload -Uz colors && colors
|
2015-12-15 00:12:17 -05:00
|
|
|
autoload -Uz add-zsh-hook
|
|
|
|
|
2017-03-01 15:18:16 -05:00
|
|
|
prompt_opts=(cr percent subst)
|
2015-12-15 00:12:17 -05:00
|
|
|
|
2015-12-15 21:51:28 -05:00
|
|
|
add-zsh-hook precmd prompt_eriner_precmd
|
2015-12-15 00:12:17 -05:00
|
|
|
|
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)'
|
|
|
|
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=''
|
2015-12-15 00:12:17 -05:00
|
|
|
}
|
|
|
|
|
2015-12-15 21:51:28 -05:00
|
|
|
prompt_eriner_setup "$@"
|