2016-07-28 02:22:44 +02:00
|
|
|
#
|
|
|
|
# magicmace theme
|
|
|
|
# Ideas and code taken from:
|
|
|
|
# xero's zsh prompt <http://code.xero.nu/dotfiles>
|
|
|
|
# eriner's eriner prompt <https://github.com/Eriner/zim/blob/master/modules/prompt/themes/eriner.zsh-theme>
|
|
|
|
#
|
|
|
|
|
|
|
|
# Global variables
|
|
|
|
function {
|
|
|
|
COLOR_ROOT="%F{red}"
|
|
|
|
COLOR_USER="%F{cyan}"
|
|
|
|
COLOR_NORMAL="%F{white}"
|
|
|
|
COLOR_ERROR="%F{red}"
|
|
|
|
|
|
|
|
if [[ "$EUID" -ne "0" ]]; then
|
2016-09-25 18:56:04 +02:00
|
|
|
COLOR_USER_LEVEL="${COLOR_USER}"
|
2016-07-28 02:22:44 +02:00
|
|
|
else
|
2016-09-25 18:56:04 +02:00
|
|
|
COLOR_USER_LEVEL="${COLOR_ROOT}"
|
2016-07-28 02:22:44 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Status:
|
|
|
|
# - was there an error?
|
|
|
|
# - are there background jobs?
|
|
|
|
# - are we in a ranger session?
|
2016-09-25 18:56:04 +02:00
|
|
|
prompt_magicmace_status() {
|
2016-07-28 02:22:44 +02:00
|
|
|
local symbols=""
|
|
|
|
|
2016-09-25 18:56:04 +02:00
|
|
|
[[ ${RETVAL} -ne 0 ]] && symbols+="${COLOR_ERROR}${RETVAL}${COLOR_NORMAL}" # $? for error.
|
2016-07-28 02:22:44 +02:00
|
|
|
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+='b' # 'b' for background.
|
|
|
|
[[ ${RANGER_LEVEL} -ne 0 ]] && symbols+='r' # 'r' for... you guessed it!
|
|
|
|
|
2016-09-25 18:56:04 +02:00
|
|
|
[[ -n ${symbols} ]] && print -n "─${COLOR_NORMAL}${symbols}${COLOR_USER_LEVEL}─"
|
2016-07-28 02:22:44 +02:00
|
|
|
}
|
|
|
|
|
2016-09-25 18:56:04 +02:00
|
|
|
prompt_magicmace_git() {
|
2016-07-28 02:22:44 +02:00
|
|
|
local ico_dirty='*'
|
|
|
|
local ico_ahead='🠙'
|
|
|
|
local ico_behind='🠛'
|
|
|
|
local ico_diverged='⥮'
|
|
|
|
local git_info=""
|
|
|
|
|
|
|
|
is_dirty() {
|
|
|
|
test -n "$(git status --porcelain --ignore-submodules)"
|
|
|
|
}
|
|
|
|
|
|
|
|
vcs_info
|
|
|
|
git_info=${vcs_info_msg_0_} # branch name
|
|
|
|
if [[ -n ${git_info} ]]; then
|
|
|
|
|
|
|
|
if is_dirty; then
|
|
|
|
git_info+=${ico_dirty}
|
|
|
|
fi
|
|
|
|
|
|
|
|
stat=$(git status 2> /dev/null | command sed -n 2p)
|
|
|
|
case "${stat}" in
|
|
|
|
*ahead*) git_info+=${ico_ahead} ;;
|
|
|
|
*behind*) git_info+=${ico_behind} ;;
|
|
|
|
*diverged*) git_info+=${ico_diverged} ;;
|
|
|
|
*);;
|
|
|
|
esac
|
|
|
|
|
2016-09-25 18:56:04 +02:00
|
|
|
print -n "─[${COLOR_NORMAL}${git_info}${COLOR_USER_LEVEL}]"
|
2016-07-28 02:22:44 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
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=$?
|
|
|
|
}
|
|
|
|
|
|
|
|
prompt_magicmace_setup() {
|
|
|
|
autoload -Uz colors && colors
|
|
|
|
autoload -Uz add-zsh-hook
|
|
|
|
autoload -Uz vcs_info
|
|
|
|
|
|
|
|
prompt_opts=(cr subst percent)
|
|
|
|
|
2016-09-25 18:56:04 +02:00
|
|
|
add-zsh-hook precmd prompt_magicmace_precmd
|
|
|
|
|
2016-07-28 02:22:44 +02:00
|
|
|
zstyle ':vcs_info:*' enable git
|
|
|
|
zstyle ':vcs_info:*' check-for-changes false
|
|
|
|
zstyle ':vcs_info:*' use-simple true
|
|
|
|
# Only export branch name, as that is the only data we need.
|
|
|
|
zstyle ':vcs_info:*' max-exports 1
|
|
|
|
zstyle ':vcs_info:git*' formats '%b'
|
|
|
|
|
|
|
|
# Call git directly, ignoring aliases under the same name.
|
|
|
|
zstyle ':vcs_info:git:*:-all-' command =git
|
2016-09-25 18:56:04 +02:00
|
|
|
PROMPT='${COLOR_USER_LEVEL}$(prompt_magicmace_status)[${COLOR_NORMAL}$(short_pwd)${COLOR_USER_LEVEL}]$(prompt_magicmace_git)── ─%f '
|
2016-07-28 02:22:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
prompt_magicmace_setup "$@"
|