Fix magicmace errors when git-info not enabled
and add a comment stating that the theme requires the `git-info` module. Also make better usage of the arithmetic command `(( ))`.
This commit is contained in:
parent
7d952adf2b
commit
213a8a1ef1
1 changed files with 11 additions and 8 deletions
|
@ -4,6 +4,7 @@
|
||||||
# xero's zsh prompt <http://code.xero.nu/dotfiles>
|
# 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>
|
# eriner's eriner prompt <https://github.com/Eriner/zim/blob/master/modules/prompt/themes/eriner.zsh-theme>
|
||||||
#
|
#
|
||||||
|
# Requires the `git-info` zmodule to be included in the .zimrc file.
|
||||||
|
|
||||||
# Global variables
|
# Global variables
|
||||||
function {
|
function {
|
||||||
|
@ -12,7 +13,7 @@ function {
|
||||||
COLOR_NORMAL="%F{white}"
|
COLOR_NORMAL="%F{white}"
|
||||||
COLOR_ERROR="%F{red}"
|
COLOR_ERROR="%F{red}"
|
||||||
|
|
||||||
if [[ ${EUID} -ne 0 ]]; then
|
if (( ${EUID} )); then
|
||||||
COLOR_USER_LEVEL=${COLOR_USER}
|
COLOR_USER_LEVEL=${COLOR_USER}
|
||||||
else
|
else
|
||||||
COLOR_USER_LEVEL=${COLOR_ROOT}
|
COLOR_USER_LEVEL=${COLOR_ROOT}
|
||||||
|
@ -26,13 +27,17 @@ function {
|
||||||
prompt_magicmace_status() {
|
prompt_magicmace_status() {
|
||||||
local symbols=""
|
local symbols=""
|
||||||
|
|
||||||
[[ ${RETVAL} -ne 0 ]] && symbols+="${COLOR_ERROR}${RETVAL}${COLOR_NORMAL}" # $? for error.
|
(( ${RETVAL} )) && symbols+="${COLOR_ERROR}${RETVAL}${COLOR_NORMAL}" # $? for error.
|
||||||
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+='b' # 'b' for background.
|
(( $(jobs -l | wc -l) > 0 )) && symbols+='b' # 'b' for background.
|
||||||
[[ ${RANGER_LEVEL} -ne 0 ]] && symbols+='r' # 'r' for... you guessed it!
|
(( ${RANGER_LEVEL} )) && symbols+='r' # 'r' for... you guessed it!
|
||||||
|
|
||||||
[[ -n ${symbols} ]] && print -n "─${COLOR_NORMAL}${symbols}${COLOR_USER_LEVEL}─"
|
[[ -n ${symbols} ]] && print -n "─${COLOR_NORMAL}${symbols}${COLOR_USER_LEVEL}─"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prompt_magicmace_git() {
|
||||||
|
[[ -n ${git_info} ]] && print -n "${(e)git_info[prompt]}"
|
||||||
|
}
|
||||||
|
|
||||||
prompt_magicmace_precmd() {
|
prompt_magicmace_precmd() {
|
||||||
# While it would be apt to have this as a local variable in prompt_status(),
|
# 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
|
# $? (returned value) and ${(%):-%?} ("The return status of the last command
|
||||||
|
@ -41,9 +46,7 @@ prompt_magicmace_precmd() {
|
||||||
# We could also just set $? as an argument, and thus get our nifty local variable,
|
# 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.
|
# but that's stretching it, and makes the code harder to read.
|
||||||
RETVAL=$?
|
RETVAL=$?
|
||||||
if [[ ${+functions[git-info]} ]]; then
|
(( ${+functions[git-info]} )) && git-info
|
||||||
git-info
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt_magicmace_setup() {
|
prompt_magicmace_setup() {
|
||||||
|
@ -63,7 +66,7 @@ prompt_magicmace_setup() {
|
||||||
'prompt' '─[${COLOR_NORMAL}%b%c%D%A%B${COLOR_USER_LEVEL}]'
|
'prompt' '─[${COLOR_NORMAL}%b%c%D%A%B${COLOR_USER_LEVEL}]'
|
||||||
|
|
||||||
# Call git directly, ignoring aliases under the same name.
|
# Call git directly, ignoring aliases under the same name.
|
||||||
PROMPT='${COLOR_USER_LEVEL}$(prompt_magicmace_status)[${COLOR_NORMAL}$(short_pwd)${COLOR_USER_LEVEL}]${(e)git_info[prompt]}── ─%f '
|
PROMPT='${COLOR_USER_LEVEL}$(prompt_magicmace_status)[${COLOR_NORMAL}$(short_pwd)${COLOR_USER_LEVEL}]$(prompt_magicmace_git)── ─%f '
|
||||||
RPROMPT=''
|
RPROMPT=''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue