1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-09-21 11:00:08 +00:00

Merge pull request #378 from bhilburn/anion155-hdd-segment

Adding new disk_usage segment, based on Anion155's hdd_usage
This commit is contained in:
Ben Hilburn 2017-01-21 21:56:27 -05:00 committed by GitHub
commit 92b1b6235a
4 changed files with 60 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -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'

View file

@ -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'