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
|
|
|
|
#
|
|
|
|
# # README
|
|
|
|
#
|
|
|
|
# In order for this theme to render correctly, you will need a
|
2015-12-29 11:19:36 -05:00
|
|
|
# font with powerline symbols. A simple way to add the powerline
|
|
|
|
# symbols is to follow the instructions here:
|
|
|
|
# https://simplyian.com/2014/03/28/using-powerline-symbols-with-your-current-font/
|
2015-12-15 00:12:17 -05:00
|
|
|
#
|
|
|
|
# # Goals
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
### Segment drawing
|
|
|
|
# A few utility functions to make it easy and re-usable to draw segmented prompts
|
|
|
|
|
|
|
|
CURRENT_BG='NONE'
|
|
|
|
PRIMARY_FG=black
|
|
|
|
|
|
|
|
# Characters
|
2015-12-18 10:11:49 -05:00
|
|
|
function {
|
|
|
|
local LC_ALL="" LC_CTYPE="en_US.UTF-8"
|
|
|
|
SEGMENT_SEPARATOR="\ue0b0"
|
|
|
|
PLUSMINUS="\u00b1"
|
|
|
|
BRANCH="\ue0a0"
|
|
|
|
DETACHED="\u27a6"
|
|
|
|
CROSS="\u2718"
|
|
|
|
LIGHTNING="\u26a1"
|
|
|
|
GEAR="\u2699"
|
|
|
|
}
|
2015-12-15 00:12:17 -05:00
|
|
|
|
|
|
|
# Begin a segment
|
|
|
|
# Takes two arguments, background and foreground. Both can be omitted,
|
|
|
|
# rendering default background/foreground.
|
|
|
|
prompt_segment() {
|
|
|
|
local bg fg
|
2015-12-15 19:21:06 -05:00
|
|
|
[[ -n ${1} ]] && bg="%K{${1}}" || bg="%k"
|
|
|
|
[[ -n ${2} ]] && fg="%F{${2}}" || fg="%f"
|
|
|
|
if [[ $CURRENT_BG != 'NONE' && ${1} != $CURRENT_BG ]]; then
|
|
|
|
print -n "%{${bg}%F{${CURRENT_BG}}%}${SEGMENT_SEPARATOR}%{${fg}%}"
|
2015-12-15 00:12:17 -05:00
|
|
|
else
|
2015-12-15 19:21:06 -05:00
|
|
|
print -n "%{${bg}%}%{${fg}%}"
|
2015-12-15 00:12:17 -05:00
|
|
|
fi
|
2015-12-15 19:21:06 -05:00
|
|
|
CURRENT_BG=${1}
|
|
|
|
[[ -n ${3} ]] && print -n ${3}
|
2015-12-15 00:12:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
# End the prompt, closing any open segments
|
|
|
|
prompt_end() {
|
|
|
|
if [[ -n $CURRENT_BG ]]; then
|
2015-12-15 19:21:06 -05:00
|
|
|
print -n "%{%k%F{${CURRENT_BG}}%}${SEGMENT_SEPARATOR}"
|
2015-12-15 00:12:17 -05:00
|
|
|
else
|
|
|
|
print -n "%{%k%}"
|
|
|
|
fi
|
|
|
|
print -n "%{%f%}"
|
|
|
|
CURRENT_BG=''
|
|
|
|
}
|
|
|
|
|
|
|
|
### Prompt components
|
|
|
|
# Each component will draw itself, and hide itself if no information needs to be shown
|
|
|
|
|
|
|
|
# Context: user@hostname (who am I and where am I)
|
|
|
|
prompt_context() {
|
2015-12-18 10:11:49 -05:00
|
|
|
if [[ ${USER} != ${DEFAULT_USER} || -n ${SSH_CONNECTION} ]]; then
|
|
|
|
prompt_segment ${PRIMARY_FG} default " %(!.%{%F{yellow}%}.)${USER}@%m "
|
2015-12-15 00:12:17 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-07-17 08:53:34 -04:00
|
|
|
# Ranger: <https://github.com/ranger/ranger>, which can spawn ${SHELL}
|
|
|
|
# under its own process
|
|
|
|
prompt_ranger() {
|
|
|
|
if [[ $((RANGER_LEVEL)) -ne 0 ]]; then
|
|
|
|
local color=blue
|
|
|
|
prompt_segment ${color} ${PRIMARY_FG}
|
|
|
|
print -Pn " r"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-12-15 00:12:17 -05:00
|
|
|
# Git: branch/detached head, dirty status
|
|
|
|
prompt_git() {
|
|
|
|
local color ref
|
|
|
|
is_dirty() {
|
2016-02-04 15:08:22 -05:00
|
|
|
test -n "$(command git status --porcelain --ignore-submodules)"
|
2015-12-15 00:12:17 -05:00
|
|
|
}
|
2015-12-15 19:21:06 -05:00
|
|
|
ref=${vcs_info_msg_0_}
|
|
|
|
if [[ -n ${ref} ]]; then
|
2015-12-15 00:12:17 -05:00
|
|
|
if is_dirty; then
|
|
|
|
color=yellow
|
2015-12-15 19:21:06 -05:00
|
|
|
ref="${ref} ${PLUSMINUS}"
|
2015-12-15 00:12:17 -05:00
|
|
|
else
|
|
|
|
color=green
|
|
|
|
ref="${ref} "
|
|
|
|
fi
|
2015-12-15 19:21:06 -05:00
|
|
|
if [[ "${ref/.../}" == ${ref} ]]; then
|
|
|
|
ref="${BRANCH} ${ref}"
|
2015-12-15 00:12:17 -05:00
|
|
|
else
|
|
|
|
ref="$DETACHED ${ref/.../}"
|
|
|
|
fi
|
2015-12-15 19:21:06 -05:00
|
|
|
prompt_segment ${color} ${PRIMARY_FG}
|
|
|
|
print -Pn " ${ref}"
|
2015-12-15 00:12:17 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Dir: current working directory
|
|
|
|
prompt_dir() {
|
2016-01-05 04:15:05 -05:00
|
|
|
prompt_segment cyan ${PRIMARY_FG} " $(short_pwd) "
|
2015-12-15 00:12:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
# Status:
|
|
|
|
# - was there an error
|
|
|
|
# - am I root
|
|
|
|
# - are there background jobs?
|
|
|
|
prompt_status() {
|
|
|
|
local symbols
|
|
|
|
symbols=()
|
2015-12-15 19:21:06 -05:00
|
|
|
[[ ${RETVAL} -ne 0 ]] && symbols+="%{%F{red}%}${CROSS}"
|
|
|
|
[[ ${UID} -eq 0 ]] && symbols+="%{%F{yellow}%}${LIGHTNING}"
|
|
|
|
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}${GEAR}"
|
2015-12-15 00:12:17 -05:00
|
|
|
|
2015-12-15 19:21:06 -05:00
|
|
|
[[ -n ${symbols} ]] && prompt_segment ${PRIMARY_FG} default " ${symbols} "
|
2015-12-15 00:12:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
## Main prompt
|
2015-12-15 21:51:28 -05:00
|
|
|
prompt_eriner_main() {
|
2015-12-15 00:12:17 -05:00
|
|
|
RETVAL=$?
|
|
|
|
CURRENT_BG='NONE'
|
|
|
|
prompt_status
|
|
|
|
prompt_context
|
2016-07-17 08:53:34 -04:00
|
|
|
prompt_ranger
|
2015-12-15 00:12:17 -05:00
|
|
|
prompt_dir
|
|
|
|
prompt_git
|
|
|
|
prompt_end
|
|
|
|
}
|
|
|
|
|
2015-12-15 21:51:28 -05:00
|
|
|
prompt_eriner_precmd() {
|
2015-12-15 00:12:17 -05:00
|
|
|
vcs_info
|
2015-12-15 21:51:28 -05:00
|
|
|
PROMPT='%{%f%b%k%}$(prompt_eriner_main) '
|
2015-12-15 00:12:17 -05:00
|
|
|
}
|
|
|
|
|
2015-12-15 21:51:28 -05:00
|
|
|
prompt_eriner_setup() {
|
2015-12-15 00:12:17 -05:00
|
|
|
autoload -Uz add-zsh-hook
|
|
|
|
autoload -Uz vcs_info
|
|
|
|
|
|
|
|
prompt_opts=(cr subst percent)
|
|
|
|
|
2015-12-15 21:51:28 -05:00
|
|
|
add-zsh-hook precmd prompt_eriner_precmd
|
2015-12-15 00:12:17 -05:00
|
|
|
|
|
|
|
zstyle ':vcs_info:*' enable git
|
|
|
|
zstyle ':vcs_info:*' check-for-changes false
|
|
|
|
zstyle ':vcs_info:git*' formats '%b'
|
|
|
|
zstyle ':vcs_info:git*' actionformats '%b (%a)'
|
|
|
|
}
|
|
|
|
|
2015-12-15 21:51:28 -05:00
|
|
|
prompt_eriner_setup "$@"
|