aboutsummaryrefslogtreecommitdiff
path: root/powerlevel9k.zsh-theme
diff options
context:
space:
mode:
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-xpowerlevel9k.zsh-theme82
1 files changed, 71 insertions, 11 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 45881876..d570da9f 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -337,6 +337,23 @@ prompt_background_jobs() {
fi
}
+# A newline in your prompt, so you can segments on multiple lines.
+prompt_newline() {
+ local lws newline
+ [[ "$1" == "right" ]] && return
+ newline=$'\n'
+ lws=$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS
+ if [[ "$POWERLEVEL9K_PROMPT_ON_NEWLINE" == true ]]; then
+ newline="${newline}$(print_icon 'MULTILINE_NEWLINE_PROMPT_PREFIX')"
+ fi
+ POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS=
+ "$1_prompt_segment" \
+ "$0" \
+ "$2" \
+ "NONE" "NONE" "${newline}"
+ POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS=$lws
+}
+
# Segment that indicates usage level of current partition.
set_default POWERLEVEL9K_DISK_USAGE_ONLY_WARNING false
set_default POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL 90
@@ -468,9 +485,24 @@ prompt_battery() {
message="$bat_percent%%"
fi
- # Draw the prompt_segment
- if [[ -n $bat_percent ]]; then
- "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${battery_states[$current_state]}" "$message" 'BATTERY_ICON'
+ # override default icon if we are using battery stages
+ if [[ -n "$POWERLEVEL9K_BATTERY_STAGES" ]]; then
+ local segment=$(( 100.0 / (${#POWERLEVEL9K_BATTERY_STAGES} - 1 ) ))
+ if [[ $segment > 1 ]]; then
+ local offset=$(( ($bat_percent / $segment) + 1 ))
+ # check if the stages are in an array or a string
+ [[ "${(t)POWERLEVEL9K_BATTERY_STAGES}" =~ "array" ]] && POWERLEVEL9K_BATTERY_ICON="$POWERLEVEL9K_BATTERY_STAGES[$offset]" || POWERLEVEL9K_BATTERY_ICON=${POWERLEVEL9K_BATTERY_STAGES:$offset:1}
+ fi
+ fi
+
+ # override the default color if we are using a color level array
+ if [[ -n "$POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND" ]] && [[ "${(t)POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND}" =~ "array" ]]; then
+ local segment=$(( 100.0 / (${#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND} - 1 ) ))
+ local offset=$(( ($bat_percent / $segment) + 1 ))
+ "$1_prompt_segment" "$0_${current_state}" "$2" "${POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND[$offset]}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON"
+ else
+ # Draw the prompt_segment
+ "$1_prompt_segment" "$0_${current_state}" "$2" "${DEFAULT_COLOR}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON"
fi
}
@@ -1004,10 +1036,30 @@ prompt_ssh() {
# Status: return code if verbose, otherwise just an icon if an error occurred
set_default POWERLEVEL9K_STATUS_VERBOSE true
set_default POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE false
+set_default POWERLEVEL9K_STATUS_SHOW_PIPESTATUS true
prompt_status() {
- if [[ "$RETVAL" -ne 0 ]]; then
+ local ec_text
+ local ec_sum
+ local ec
+
+ if [[ $POWERLEVEL9K_STATUS_SHOW_PIPESTATUS == true ]]; then
+ ec_text=${RETVALS[1]}
+ ec_sum=${RETVALS[1]}
+
+ for ec in "${(@)RETVALS[2,-1]}"; do
+ ec_text="${ec_text}|${ec}"
+ ec_sum=$(( $ec_sum + $ec ))
+ done
+ else
+ # We use RETVAL instead of the right-most RETVALS item because
+ # PIPE_FAIL may be set.
+ ec_text=${RETVAL}
+ ec_sum=${RETVAL}
+ fi
+
+ if (( ec_sum > 0 )); then
if [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true ]]; then
- "$1_prompt_segment" "$0_ERROR" "$2" "red" "226" "$RETVAL" 'CARRIAGE_RETURN_ICON'
+ "$1_prompt_segment" "$0_ERROR" "$2" "red" "226" "$ec_text" 'CARRIAGE_RETURN_ICON'
else
"$1_prompt_segment" "$0_ERROR" "$2" "$DEFAULT_COLOR" "red" "" 'FAIL_ICON'
fi
@@ -1291,15 +1343,16 @@ powerlevel9k_preexec() {
set_default POWERLEVEL9K_PROMPT_ADD_NEWLINE false
powerlevel9k_prepare_prompts() {
RETVAL=$?
+ RETVALS=( "$pipestatus[@]" )
_P9K_COMMAND_DURATION=$((EPOCHREALTIME - _P9K_TIMER_START))
# Reset start time
- _P9K_TIMER_START=0xFFFFFFFF
+ _P9K_TIMER_START=0x7FFFFFFF
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')'
+$(print_icon 'MULTILINE_LAST_PROMPT_PREFIX')'
if [[ "$POWERLEVEL9K_RPROMPT_ON_NEWLINE" != true ]]; then
# 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
@@ -1328,12 +1381,12 @@ NEWLINE='
}
prompt_powerlevel9k_setup() {
- # I decided to use the value below for better supporting 32-bit CPUs, since the previous value "99999999999" was causing issues on my Android phone, which is powered by an armv7l
- # We don't have to change that until 19 January of 2038! :)
+ # The value below was set to better support 32-bit CPUs.
+ # It's the maximum _signed_ integer value on 32-bit CPUs.
+ # Please don't change it until 19 January of 2038. ;)
# Disable false display of command execution time
- # Maximum integer on 32-bit CPUs
- _P9K_TIMER_START=2147483647
+ _P9K_TIMER_START=0x7FFFFFFF
# The prompt function will set these prompt_* options after the setup function
# returns. We need prompt_subst so we can safely run commands in the prompt
@@ -1397,4 +1450,11 @@ prompt_powerlevel9k_setup() {
add-zsh-hook preexec powerlevel9k_preexec
}
+prompt_powerlevel9k_teardown() {
+ add-zsh-hook -D precmd powerlevel9k_\*
+ add-zsh-hook -D preexec powerlevel9k_\*
+ PROMPT='%m%# '
+ RPROMPT=
+}
+
prompt_powerlevel9k_setup "$@"