speed up disk_usage prompt
parent
3ca1477bd8
commit
99457a4ad5
|
@ -428,41 +428,24 @@ set_default POWERLEVEL9K_DISK_USAGE_ONLY_WARNING false
|
||||||
set_default -i POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL 90
|
set_default -i POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL 90
|
||||||
set_default -i POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL 95
|
set_default -i POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL 95
|
||||||
prompt_disk_usage() {
|
prompt_disk_usage() {
|
||||||
local current_state="unknown"
|
(( $+commands[df] )) || return
|
||||||
typeset -AH hdd_usage_forecolors
|
local disk_usage=${${=${(f)"$(command df -P .)"}[2]}[5]%%%}
|
||||||
hdd_usage_forecolors=(
|
local state bg fg
|
||||||
'normal' 'yellow'
|
if (( disk_usage >= POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL )); then
|
||||||
'warning' "$DEFAULT_COLOR"
|
state=critical
|
||||||
'critical' 'white'
|
bg=red
|
||||||
)
|
fg=white
|
||||||
typeset -AH hdd_usage_backcolors
|
elif (( disk_usage >= POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL )); then
|
||||||
hdd_usage_backcolors=(
|
state=warning
|
||||||
'normal' $DEFAULT_COLOR
|
bg=yellow
|
||||||
'warning' 'yellow'
|
fg=$DEFAULT_COLOR
|
||||||
'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
|
else
|
||||||
if [[ "$POWERLEVEL9K_DISK_USAGE_ONLY_WARNING" == true ]]; then
|
[[ "$POWERLEVEL9K_DISK_USAGE_ONLY_WARNING" == true ]] && return
|
||||||
current_state=''
|
state=normal
|
||||||
return
|
bg=$DEFAULT_COLOR
|
||||||
fi
|
fg=yellow
|
||||||
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]}" 'DISK_ICON' 0 '' "$message"
|
|
||||||
fi
|
fi
|
||||||
|
$1_prompt_segment $0_$state $2 $bg $fg DISK_ICON 0 '' "$disk_usage%%"
|
||||||
}
|
}
|
||||||
|
|
||||||
################################################################
|
################################################################
|
||||||
|
|
Loading…
Reference in New Issue