[prompt] magicmace: fix tab completion
The offender was `print -P`, where `-P` does [prompt expansion](http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Prompt-Expansion). I took the freedom to also change a few things: Move the `add-zsh-hook precmd` up, add `prompt_magicmace_` prefix to all function names, add `COLOR_` prefix to all color global variables, and move assignment to `PROMPT` to `prompt_magicmace_setup`. Fixes #70, Closes #81
This commit is contained in:
parent
071ddaf0ac
commit
40ef228286
1 changed files with 10 additions and 12 deletions
|
@ -13,9 +13,9 @@ function {
|
||||||
COLOR_ERROR="%F{red}"
|
COLOR_ERROR="%F{red}"
|
||||||
|
|
||||||
if [[ "$EUID" -ne "0" ]]; then
|
if [[ "$EUID" -ne "0" ]]; then
|
||||||
USER_LEVEL="${COLOR_USER}"
|
COLOR_USER_LEVEL="${COLOR_USER}"
|
||||||
else
|
else
|
||||||
USER_LEVEL="${COLOR_ROOT}"
|
COLOR_USER_LEVEL="${COLOR_ROOT}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,17 +23,17 @@ function {
|
||||||
# - was there an error?
|
# - was there an error?
|
||||||
# - are there background jobs?
|
# - are there background jobs?
|
||||||
# - are we in a ranger session?
|
# - are we in a ranger session?
|
||||||
prompt_status() {
|
prompt_magicmace_status() {
|
||||||
local symbols=""
|
local symbols=""
|
||||||
|
|
||||||
[[ ${RETVAL} -ne 0 ]] && symbols+='${COLOR_ERROR}${RETVAL}${COLOR_NORMAL}' # 'e' for error.
|
[[ ${RETVAL} -ne 0 ]] && symbols+="${COLOR_ERROR}${RETVAL}${COLOR_NORMAL}" # $? for error.
|
||||||
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+='b' # 'b' for background.
|
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+='b' # 'b' for background.
|
||||||
[[ ${RANGER_LEVEL} -ne 0 ]] && symbols+='r' # 'r' for... you guessed it!
|
[[ ${RANGER_LEVEL} -ne 0 ]] && symbols+='r' # 'r' for... you guessed it!
|
||||||
|
|
||||||
[[ -n ${symbols} ]] && print -Pn "─${COLOR_NORMAL}${symbols}${COLOR_USER}─"
|
[[ -n ${symbols} ]] && print -n "─${COLOR_NORMAL}${symbols}${COLOR_USER_LEVEL}─"
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt_git() {
|
prompt_magicmace_git() {
|
||||||
local ico_dirty='*'
|
local ico_dirty='*'
|
||||||
local ico_ahead='🠙'
|
local ico_ahead='🠙'
|
||||||
local ico_behind='🠛'
|
local ico_behind='🠛'
|
||||||
|
@ -60,8 +60,7 @@ prompt_git() {
|
||||||
*);;
|
*);;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
print -Pn \
|
print -n "─[${COLOR_NORMAL}${git_info}${COLOR_USER_LEVEL}]"
|
||||||
"${USER_LEVEL}─[${COLOR_NORMAL}${git_info}${USER_LEVEL}]"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,8 +72,6 @@ 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=$?
|
||||||
|
|
||||||
PROMPT='${USER_LEVEL}$(prompt_status)[${COLOR_NORMAL}$(short_pwd)${USER_LEVEL}]$(prompt_git)── -%f '
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt_magicmace_setup() {
|
prompt_magicmace_setup() {
|
||||||
|
@ -84,6 +81,8 @@ prompt_magicmace_setup() {
|
||||||
|
|
||||||
prompt_opts=(cr subst percent)
|
prompt_opts=(cr subst percent)
|
||||||
|
|
||||||
|
add-zsh-hook precmd prompt_magicmace_precmd
|
||||||
|
|
||||||
zstyle ':vcs_info:*' enable git
|
zstyle ':vcs_info:*' enable git
|
||||||
zstyle ':vcs_info:*' check-for-changes false
|
zstyle ':vcs_info:*' check-for-changes false
|
||||||
zstyle ':vcs_info:*' use-simple true
|
zstyle ':vcs_info:*' use-simple true
|
||||||
|
@ -93,8 +92,7 @@ prompt_magicmace_setup() {
|
||||||
|
|
||||||
# Call git directly, ignoring aliases under the same name.
|
# Call git directly, ignoring aliases under the same name.
|
||||||
zstyle ':vcs_info:git:*:-all-' command =git
|
zstyle ':vcs_info:git:*:-all-' command =git
|
||||||
|
PROMPT='${COLOR_USER_LEVEL}$(prompt_magicmace_status)[${COLOR_NORMAL}$(short_pwd)${COLOR_USER_LEVEL}]$(prompt_magicmace_git)── ─%f '
|
||||||
add-zsh-hook precmd prompt_magicmace_precmd
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt_magicmace_setup "$@"
|
prompt_magicmace_setup "$@"
|
||||||
|
|
Loading…
Reference in a new issue