aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md5
-rw-r--r--README.md55
-rw-r--r--functions/icons.zsh4
-rw-r--r--functions/utilities.zsh4
-rwxr-xr-xpowerlevel9k.zsh-theme31
5 files changed, 88 insertions, 11 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6257416b..e37e5c0a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+## v0.6.4
+
+- Significant enhancements to the `battery` segment. Check out the README to
+ read more!
+
## v0.6.3
- Fixed susceptibility to [pw3nage exploit](https://github.com/njhartwell/pw3nage).
diff --git a/README.md b/README.md
index 1f7dcadb..caeeccbb 100644
--- a/README.md
+++ b/README.md
@@ -184,9 +184,8 @@ your `~/.zshrc`:
##### battery
-This segment will display your current battery status (fails gracefully on
-systems without a battery). It is supported on both OSX and Linux (note that it
-requires `acpi` on Linux).
+The default settings for this segment will display your current battery status (fails gracefully on
+systems without a battery). It is supported on both OSX and Linux (note that it requires `acpi` on Linux).
| Variable | Default Value | Description |
|----------|---------------|-------------|
@@ -201,6 +200,56 @@ Note that you can [modify the `_FOREGROUND`
color](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt#segment-color-customization)
without affecting the icon color.
+You can also change the battery icon automatically depending on the battery
+level. This will override the default battery icon. In order to do this, you
+need to define the `POWERLEVEL9k_BATTERY_STAGES` variable.
+
+| Variable | Default Value | Description |
+| `POWERLEVEL9K_BATTERY_STAGES`|Unset|A string or array, which each index indicates a charge level.|
+
+Powerlevel9k will use each index of the string or array as a stage to indicate battery
+charge level, progressing from left to right. You can provide any number of
+stages. The setting below, for example, provides 8 stages for Powerlevel9k to use.
+```zsh
+POWERLEVEL9K_BATTERY_STAGES="▁▂▃▄▅▆▇█"
+```
+
+If you require extra spacing after the icon, you will have to set it as an array,
+since spaces in the string will be used as one of the stages and you will get a
+missing icon. To do this, declare the variable as follows:
+```zsh
+POWERLEVEL9K_BATTERY_STAGES=($'\u2581 ' $'\u2582 ' $'\u2583 ' $'\u2584 ' $'\u2585 ' $'\u2586 ' $'\u2587 ' $'\u2588 ')
+```
+
+Using the array syntax, you can create stages comprised of multiple characters.
+The below setting provides 40 battery stages.
+```zsh
+POWERLEVEL9K_BATTERY_STAGES=(
+ $'▏ ▏' $'▎ ▏' $'▍ ▏' $'▌ ▏' $'▋ ▏' $'▊ ▏' $'▉ ▏' $'█ ▏'
+ $'█▏ ▏' $'█▎ ▏' $'█▍ ▏' $'█▌ ▏' $'█▋ ▏' $'█▊ ▏' $'█▉ ▏' $'██ ▏'
+ $'██ ▏' $'██▎ ▏' $'██▍ ▏' $'██▌ ▏' $'██▋ ▏' $'██▊ ▏' $'██▉ ▏' $'███ ▏'
+ $'███ ▏' $'███▎ ▏' $'███▍ ▏' $'███▌ ▏' $'███▋ ▏' $'███▊ ▏' $'███▉ ▏' $'████ ▏'
+ $'████ ▏' $'████▎▏' $'████▍▏' $'████▌▏' $'████▋▏' $'████▊▏' $'████▉▏' $'█████▏' )
+```
+
+You can also change the background of the segment automatically depending on the
+battery level. This will override the following variables:
+`POWERLEVEL9K_BATTERY_CHARGING`, `POWERLEVEL9K_BATTERY_CHARGED`,
+`POWERLEVEL9K_BATTERY_DISCONNECTED`, and `POWERLEVEL9K_BATTERY_LOW_COLOR`. In
+order to do this, define a color array, from low to high, as shown below:
+```zsh
+POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND=(196 202 208 214 220 226 190 154 118 82 46)
+```
+
+As with the battery stages, you can use any number of colors and Powerlevel9k
+will automatically use all of them appropriately.
+
+Some example settings:
+|Brightness|Possible Array|
+|Bright Colors|(196 202 208 214 220 226 190 154 118 82 46)|
+|Normal Colors|(124 130 136 142 148 112 76 40 34 28 22)|
+|Subdued Colors|( 88 94 100 106 70 34 28 22)|
+
##### command_execution_time
Display the time the previous command took to execute if the time is above
diff --git a/functions/icons.zsh b/functions/icons.zsh
index c2cdcba5..7b3bba78 100644
--- a/functions/icons.zsh
+++ b/functions/icons.zsh
@@ -42,6 +42,7 @@ case $POWERLEVEL9K_MODE in
MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500'
MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 '
APPLE_ICON $'\uE26E' # 
+ WINDOWS_ICON $'\uE26F' # 
FREEBSD_ICON $'\U1F608 ' # 😈
ANDROID_ICON $'\uE270' # 
LINUX_ICON $'\uE271' # 
@@ -112,6 +113,7 @@ case $POWERLEVEL9K_MODE in
MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─
MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─
APPLE_ICON $'\uF179' # 
+ WINDOWS_ICON $'\uF17A' # 
FREEBSD_ICON $'\U1F608 ' # 😈
ANDROID_ICON $'\uE17B' # 
LINUX_ICON $'\uF17C' # 
@@ -178,6 +180,7 @@ case $POWERLEVEL9K_MODE in
MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─
MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─
APPLE_ICON $'\uF179' # 
+ WINDOWS_ICON $'\uF17A' # 
FREEBSD_ICON $'\UF30E ' # 
ANDROID_ICON $'\uF17B' # 
LINUX_ICON $'\uF17C' # 
@@ -244,6 +247,7 @@ case $POWERLEVEL9K_MODE in
MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\u2500'
MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\u2500 '
APPLE_ICON 'OSX'
+ WINDOWS_ICON 'WIN'
FREEBSD_ICON 'BSD'
ANDROID_ICON 'And'
LINUX_ICON 'Lx'
diff --git a/functions/utilities.zsh b/functions/utilities.zsh
index 86e5ba0e..9bd82060 100644
--- a/functions/utilities.zsh
+++ b/functions/utilities.zsh
@@ -85,6 +85,10 @@ case $(uname) in
OS='OSX'
OS_ICON=$(print_icon 'APPLE_ICON')
;;
+ CYGWIN_NT-*)
+ OS='Windows'
+ OS_ICON=$(print_icon 'WINDOWS_ICON')
+ ;;
FreeBSD)
OS='BSD'
OS_ICON=$(print_icon 'FREEBSD_ICON')
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 19da5bc9..2d664911 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -468,9 +468,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
}
@@ -1295,7 +1310,7 @@ powerlevel9k_prepare_prompts() {
_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)
@@ -1328,12 +1343,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