2016-07-27 20:22:44 -04:00
|
|
|
#
|
|
|
|
# magicmace theme
|
|
|
|
# Ideas and code taken from:
|
|
|
|
# xero's zsh prompt <http://code.xero.nu/dotfiles>
|
2018-01-01 07:58:41 -05:00
|
|
|
# eriner's eriner prompt <https://github.com/zimfw/zimfw/blob/master/modules/prompt/themes/eriner.zsh-theme>
|
2016-07-27 20:22:44 -04:00
|
|
|
#
|
2017-03-02 09:06:47 -05:00
|
|
|
# Requires the `git-info` zmodule to be included in the .zimrc file.
|
2016-07-27 20:22:44 -04:00
|
|
|
|
|
|
|
# Global variables
|
|
|
|
function {
|
|
|
|
COLOR_ROOT="%F{red}"
|
|
|
|
COLOR_USER="%F{cyan}"
|
|
|
|
COLOR_NORMAL="%F{white}"
|
|
|
|
COLOR_ERROR="%F{red}"
|
|
|
|
|
2017-03-02 09:06:47 -05:00
|
|
|
if (( ${EUID} )); then
|
2016-12-02 17:20:46 -05:00
|
|
|
COLOR_USER_LEVEL=${COLOR_USER}
|
2016-07-27 20:22:44 -04:00
|
|
|
else
|
2016-12-02 17:20:46 -05:00
|
|
|
COLOR_USER_LEVEL=${COLOR_ROOT}
|
2016-07-27 20:22:44 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Status:
|
|
|
|
# - was there an error?
|
|
|
|
# - are there background jobs?
|
|
|
|
# - are we in a ranger session?
|
2016-09-25 12:56:04 -04:00
|
|
|
prompt_magicmace_status() {
|
2016-07-27 20:22:44 -04:00
|
|
|
local symbols=""
|
|
|
|
|
2017-03-02 09:06:47 -05:00
|
|
|
(( ${RETVAL} )) && symbols+="${COLOR_ERROR}${RETVAL}${COLOR_NORMAL}" # $? for error.
|
|
|
|
(( $(jobs -l | wc -l) > 0 )) && symbols+='b' # 'b' for background.
|
|
|
|
(( ${RANGER_LEVEL} )) && symbols+='r' # 'r' for... you guessed it!
|
2016-07-27 20:22:44 -04:00
|
|
|
|
2016-09-25 12:56:04 -04:00
|
|
|
[[ -n ${symbols} ]] && print -n "─${COLOR_NORMAL}${symbols}${COLOR_USER_LEVEL}─"
|
2016-07-27 20:22:44 -04:00
|
|
|
}
|
|
|
|
|
2017-03-02 09:06:47 -05:00
|
|
|
prompt_magicmace_git() {
|
|
|
|
[[ -n ${git_info} ]] && print -n "${(e)git_info[prompt]}"
|
|
|
|
}
|
|
|
|
|
2016-07-27 20:22:44 -04:00
|
|
|
prompt_magicmace_precmd() {
|
|
|
|
# While it would be apt to have this as a local variable in prompt_status(),
|
|
|
|
# $? (returned value) and ${(%):-%?} ("The return status of the last command
|
|
|
|
# executed just before the prompt") both change before executing the function.
|
|
|
|
# Is this perhaps because prompt_status _is_ here?
|
|
|
|
# We could also just set $? as an argument, and thus get our nifty local variable,
|
|
|
|
# but that's stretching it, and makes the code harder to read.
|
|
|
|
RETVAL=$?
|
2017-03-02 09:06:47 -05:00
|
|
|
(( ${+functions[git-info]} )) && git-info
|
2016-07-27 20:22:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
prompt_magicmace_setup() {
|
|
|
|
autoload -Uz colors && colors
|
|
|
|
autoload -Uz add-zsh-hook
|
|
|
|
|
2017-10-01 21:35:47 -04:00
|
|
|
prompt_opts=(cr percent sp subst)
|
2016-07-27 20:22:44 -04:00
|
|
|
|
2016-09-25 12:56:04 -04:00
|
|
|
add-zsh-hook precmd prompt_magicmace_precmd
|
|
|
|
|
2016-12-02 17:20:46 -05:00
|
|
|
zstyle ':zim:git-info:branch' format '%b'
|
|
|
|
zstyle ':zim:git-info:commit' format '%c...'
|
|
|
|
zstyle ':zim:git-info:dirty' format '*'
|
|
|
|
zstyle ':zim:git-info:ahead' format '↑'
|
|
|
|
zstyle ':zim:git-info:behind' format '↓'
|
|
|
|
zstyle ':zim:git-info:keys' format \
|
|
|
|
'prompt' '─[${COLOR_NORMAL}%b%c%D%A%B${COLOR_USER_LEVEL}]'
|
2016-07-27 20:22:44 -04:00
|
|
|
|
|
|
|
# Call git directly, ignoring aliases under the same name.
|
2017-03-02 09:06:47 -05:00
|
|
|
PROMPT='${COLOR_USER_LEVEL}$(prompt_magicmace_status)[${COLOR_NORMAL}$(short_pwd)${COLOR_USER_LEVEL}]$(prompt_magicmace_git)── ─%f '
|
2016-12-02 17:20:46 -05:00
|
|
|
RPROMPT=''
|
2016-07-27 20:22:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
prompt_magicmace_setup "$@"
|