aboutsummaryrefslogtreecommitdiff
path: root/powerlevel9k.zsh-theme
diff options
context:
space:
mode:
authorDominik Ritter <dritter03@googlemail.com>2015-09-13 00:46:46 +0300
committerDominik Ritter <dritter03@googlemail.com>2015-09-13 00:46:46 +0300
commitc8e41ad4ee3644731f8985874ed34407d0865528 (patch)
treee62a7d461c1a844e01556d7b604d5fdc7bfd1f3c /powerlevel9k.zsh-theme
parentd1336807049fcb8ca00196c290a77a9468dfef8c (diff)
Simplified the way the build-prompt-functions are called. Before it was quite obscure how and when ZSH called the right functions. It was a matter of a complex quote syntax. Now, by adding a new precmd-hook, the use of the quotes in the PROMPT and RPROMPT-variables is much simpler.
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rw-r--r--powerlevel9k.zsh-theme52
1 files changed, 27 insertions, 25 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 57c204dc..55a6e14c 100644
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -661,7 +661,7 @@ prompt_longstatus() {
symbols=()
if [[ "$RETVAL" -ne 0 ]]; then
- symbols+="%F{226}%? ↵"
+ symbols+="%F{226}$RETVAL ↵"
bg="009"
else
symbols+="%{%F{046}%}$(print_icon 'OK_ICON')"
@@ -798,8 +798,6 @@ prompt_virtualenv() {
# Main prompt
build_left_prompt() {
- RETVAL=$?
-
defined POWERLEVEL9K_LEFT_PROMPT_ELEMENTS || POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir rbenv vcs)
for element in "${POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[@]}"; do
@@ -811,8 +809,6 @@ build_left_prompt() {
# Right prompt
build_right_prompt() {
- RETVAL=$?
-
defined POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS || POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(longstatus history time)
for element in "${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[@]}"; do
@@ -820,6 +816,30 @@ build_right_prompt() {
done
}
+powerlevel9k_prepare_prompts() {
+ RETVAL=$?
+
+ if [[ "$POWERLEVEL9K_PROMPT_ON_NEWLINE" == true ]]; then
+ PROMPT="$(print_icon 'MULTILINE_FIRST_PROMPT_PREFIX')%{%f%b%k%}$(build_left_prompt)
+$(print_icon 'MULTILINE_SECOND_PROMPT_PREFIX')"
+ # The right prompt should be on the same line as the first line of the left
+ # prompt. To do so, there is just a quite ugly workaround: Before zsh draws
+ # the RPROMPT, we advise it, to go one line up. At the end of RPROMPT, we
+ # advise it to go one line down. See:
+ # http://superuser.com/questions/357107/zsh-right-justify-in-ps1
+ RPROMPT_PREFIX='%{'$'\e[1A''%}' # one line up
+ RPROMPT_SUFFIX='%{'$'\e[1B''%}' # one line down
+ else
+ PROMPT="%{%f%b%k%}$(build_left_prompt)"
+ RPROMPT_PREFIX=''
+ RPROMPT_SUFFIX=''
+ fi
+
+ if [[ "$POWERLEVEL9K_DISABLE_RPROMPT" != true ]]; then
+ RPROMPT="$RPROMPT_PREFIX%{%f%b%k%}$(build_right_prompt)%{$reset_color%}$RPROMPT_SUFFIX"
+ fi
+}
+
powerlevel9k_init() {
# Display a warning if the terminal does not support 256 colors
local term_colors
@@ -838,28 +858,10 @@ powerlevel9k_init() {
# initialize VCS
autoload -Uz add-zsh-hook
-
add-zsh-hook precmd vcs_info
- if [[ "$POWERLEVEL9K_PROMPT_ON_NEWLINE" == true ]]; then
- PROMPT="$(print_icon 'MULTILINE_FIRST_PROMPT_PREFIX')%{%f%b%k%}"'$(build_left_prompt)'"
-$(print_icon 'MULTILINE_SECOND_PROMPT_PREFIX')"
- # The right prompt should be on the same line as the first line of the left
- # prompt. To do so, there is just a quite ugly workaround: Before zsh draws
- # the RPROMPT, we advise it, to go one line up. At the end of RPROMPT, we
- # advise it to go one line down. See:
- # http://superuser.com/questions/357107/zsh-right-justify-in-ps1
- RPROMPT_PREFIX='%{'$'\e[1A''%}' # one line up
- RPROMPT_SUFFIX='%{'$'\e[1B''%}' # one line down
- else
- PROMPT="%{%f%b%k%}"'$(build_left_prompt)'
- RPROMPT_PREFIX=''
- RPROMPT_SUFFIX=''
- fi
-
- if [[ "$POWERLEVEL9K_DISABLE_RPROMPT" != true ]]; then
- RPROMPT=$RPROMPT_PREFIX"%{%f%b%k%}"'$(build_right_prompt)'"%{$reset_color%}"$RPROMPT_SUFFIX
- fi
+ # prepare prompts
+ add-zsh-hook precmd powerlevel9k_prepare_prompts
}
powerlevel9k_init "$@"