aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Hilburn <bhilburn@gmail.com>2017-01-22 05:56:27 +0300
committerGitHub <noreply@github.com>2017-01-22 05:56:27 +0300
commit92b1b6235af2f63dcdac5805d1f928ef5a726938 (patch)
treea435ef43aa1005da4a78ae5e735509f59e40ec07
parent9ead1c15480249b082bf93c59540f4a09fa44c8d (diff)
parent81e9fef9e9ed95499c572415eaa78b343746068f (diff)
Merge pull request #378 from bhilburn/anion155-hdd-segment
Adding new disk_usage segment, based on Anion155's hdd_usage
-rw-r--r--CHANGELOG.md4
-rw-r--r--README.md11
-rw-r--r--functions/icons.zsh3
-rwxr-xr-xpowerlevel9k.zsh-theme42
4 files changed, 60 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8060e0fa..ff0fd890 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,10 @@ Added an option to configure the path separator. If you want something
else than an ordinary slash, you could set
`POWERLEVEL9K_DIR_PATH_SEPARATOR` to whatever you want.
+### New segment 'disk_usage' added
+
+This segment will show the usage level of your current partition.
+
## v0.5.0
### `load` and `ram` changes
diff --git a/README.md b/README.md
index f6b8c54c..0d3eb303 100644
--- a/README.md
+++ b/README.md
@@ -88,6 +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.
+* [`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.
@@ -306,6 +307,16 @@ If you want to customize the directory separator, you could set:
POWERLEVEL9K_DIR_PATH_SEPARATOR="%f "$'\uE0B1'" %F"
```
+##### disk_usage
+
+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_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
This segment tries to examine all currently used network interfaces and prints
diff --git a/functions/icons.zsh b/functions/icons.zsh
index 43847427..df92d22a 100644
--- a/functions/icons.zsh
+++ b/functions/icons.zsh
@@ -34,6 +34,7 @@ case $POWERLEVEL9K_MODE in
TEST_ICON $'\uE891' # 
TODO_ICON $'\u2611' # ☑
BATTERY_ICON $'\uE894' # 
+ DISK_ICON $'\uE1AE ' # 
OK_ICON $'\u2713' # ✓
FAIL_ICON $'\u2718' # ✘
SYMFONY_ICON 'SF'
@@ -97,6 +98,7 @@ case $POWERLEVEL9K_MODE in
TEST_ICON $'\uF291' # 
TODO_ICON $'\u2611' # ☑
BATTERY_ICON $'\U1F50B' # 🔋
+ DISK_ICON $'\uF0A0 ' # 
OK_ICON $'\u2713' # ✓
FAIL_ICON $'\u2718' # ✘
SYMFONY_ICON 'SF'
@@ -156,6 +158,7 @@ case $POWERLEVEL9K_MODE in
TEST_ICON ''
TODO_ICON $'\u2611' # ☑
BATTERY_ICON $'\U1F50B' # 🔋
+ DISK_ICON $'hdd '
OK_ICON $'\u2713' # ✓
FAIL_ICON $'\u2718' # ✘
SYMFONY_ICON 'SF'
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index c3f2be74..f2e32582 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -337,6 +337,48 @@ prompt_background_jobs() {
fi
}
+# Segment that indicates usage level of current partition.
+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=(
+ 'normal' 'yellow'
+ 'warning' "$DEFAULT_COLOR"
+ 'critical' 'white'
+ )
+ typeset -AH hdd_usage_backcolors
+ hdd_usage_backcolors=(
+ 'normal' $DEFAULT_COLOR
+ 'warning' 'yellow'
+ 'critical' 'red'
+ )
+
+ local disk_usage="${$(\df -P . | sed -n '2p' | awk '{ print $5 }')%%\%}"
+
+ if [ "$disk_usage" -ge "$POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL" ]; then
+ current_state='warning'
+ if [ "$disk_usage" -ge "$POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL" ]; then
+ current_state='critical'
+ fi
+ else
+ if [[ "$POWERLEVEL9K_DISK_USAGE_ONLY_WARNING" == true ]]; then
+ current_state=''
+ return
+ fi
+ current_state='normal'
+ fi
+
+ local message="${disk_usage}%%"
+
+ # Draw the prompt_segment
+ 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
+}
+
prompt_battery() {
# The battery can have four different states - default to 'unknown'.
local current_state='unknown'