From 7bd2585371cc28a460543f8ef37c9f93c0d188df Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Sat, 21 Jan 2017 21:34:55 -0500 Subject: [PATCH] incorportaing feedback from review on `hdd_usage` segment --- README.md | 12 ++++++------ functions/icons.zsh | 6 +++--- powerlevel9k.zsh-theme | 23 ++++++++++++----------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index b1bdf978..0d3eb303 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ The segments that are currently available are: * [`battery`](#battery) - Current battery status. * [`context`](#context) - Your username and host. * [`dir`](#dir) - Your current working directory. -* [`hdd_usage`](#hdd_usage) - Disk usage of your current partition. +* [`disk_usage`](#disk_usage) - Disk usage of your current partition. * `history` - The command number for the current line. * [`ip`](#ip) - Shows the current IP address. * [`public_ip`](#public_ip) - Shows your public IP address. @@ -307,15 +307,15 @@ If you want to customize the directory separator, you could set: POWERLEVEL9K_DIR_PATH_SEPARATOR="%f "$'\uE0B1'" %F" ``` -##### hdd_usage +##### disk_usage -The `hdd_usage` segment will show the usage level of the partition that your current working directory resides in. It can be configured with the following variables. +The `disk_usage` segment will show the usage level of the partition that your current working directory resides in. It can be configured with the following variables. | Variable | Default Value | Description | |----------|---------------|-------------| -|POWERLEVEL9K_HDD_USAGE_ONLY_WARNING|false|Hide the segment except when usage levels have hit warning or critical levels.| -|POWERLEVEL9K_HDD_USAGE_WARNING_LEVEL|90|The usage level that triggers a warning state.| -|POWERLEVEL9K_HDD_USAGE_CRITICAL_LEVEL|95|The usage level that triggers a critical state.| +|POWERLEVEL9K_DISK_USAGE_ONLY_WARNING|false|Hide the segment except when usage levels have hit warning or critical levels.| +|POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL|90|The usage level that triggers a warning state.| +|POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL|95|The usage level that triggers a critical state.| ##### ip diff --git a/functions/icons.zsh b/functions/icons.zsh index d2ca9488..84483b40 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -34,7 +34,7 @@ case $POWERLEVEL9K_MODE in TEST_ICON $'\uE891' #  TODO_ICON $'\u2611' # ☑ BATTERY_ICON $'\uE894' #  - HDD_ICON $'\uF0A0 ' #  + DISK_ICON $'\uE1AE ' #  OK_ICON $'\u2713' # ✓ FAIL_ICON $'\u2718' # ✘ SYMFONY_ICON 'SF' @@ -98,7 +98,7 @@ case $POWERLEVEL9K_MODE in TEST_ICON $'\uF291' #  TODO_ICON $'\u2611' # ☑ BATTERY_ICON $'\U1F50B' # 🔋 - HDD_ICON $'\uF0A0 ' #  + DISK_ICON $'\uF0A0 ' #  OK_ICON $'\u2713' # ✓ FAIL_ICON $'\u2718' # ✘ SYMFONY_ICON 'SF' @@ -158,7 +158,7 @@ case $POWERLEVEL9K_MODE in TEST_ICON '' TODO_ICON $'\u2611' # ☑ BATTERY_ICON $'\U1F50B' # 🔋 - HDD_ICON $'HDD ' + DISK_ICON $'hdd ' OK_ICON $'\u2713' # ✓ FAIL_ICON $'\u2718' # ✘ SYMFONY_ICON 'SF' diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index ec4c60c3..f2e32582 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -338,10 +338,10 @@ prompt_background_jobs() { } # Segment that indicates usage level of current partition. -set_default POWERLEVEL9K_HDD_USAGE_ONLY_WARNING false -set_default POWERLEVEL9K_HDD_USAGE_WARNING_LEVEL 90 -set_default POWERLEVEL9K_HDD_USAGE_CRITICAL_LEVEL 95 -prompt_hdd_usage() { +set_default POWERLEVEL9K_DISK_USAGE_ONLY_WARNING false +set_default POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL 90 +set_default POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL 95 +prompt_disk_usage() { local current_state="unknown" typeset -AH hdd_usage_forecolors hdd_usage_forecolors=( @@ -356,25 +356,26 @@ prompt_hdd_usage() { 'critical' 'red' ) - local level="${$(df -k . | sed -n '2p' | awk '{ print $5 }')%%\%}" + local disk_usage="${$(\df -P . | sed -n '2p' | awk '{ print $5 }')%%\%}" - if [ "$level" -ge "$POWERLEVEL9K_HDD_USAGE_WARNING_LEVEL" ]; then + if [ "$disk_usage" -ge "$POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL" ]; then current_state='warning' - if [ "$level" -ge "$POWERLEVEL9K_HDD_USAGE_CRITICAL_LEVEL" ]; then + if [ "$disk_usage" -ge "$POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL" ]; then current_state='critical' fi else - if [[ "$POWERLEVEL9K_HDD_USAGE_ONLY_WARNING" != false ]]; then + if [[ "$POWERLEVEL9K_DISK_USAGE_ONLY_WARNING" == true ]]; then + current_state='' return fi current_state='normal' fi - local message="${level}%%" + local message="${disk_usage}%%" # Draw the prompt_segment - if [[ -n $level ]]; then - "$1_prompt_segment" "${0}_${current_state}" "$2" "${hdd_usage_backcolors[$current_state]}" "${hdd_usage_forecolors[$current_state]}" "$message" 'HDD_ICON' + if [[ -n $disk_usage ]]; then + "$1_prompt_segment" "${0}_${current_state}" "$2" "${hdd_usage_backcolors[$current_state]}" "${hdd_usage_forecolors[$current_state]}" "$message" 'DISK_ICON' fi }