mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-11-16 09:50:06 +00:00
speed up detect_virt prompt; plus cleanup
This commit is contained in:
parent
f4df65c172
commit
1062033184
1 changed files with 12 additions and 15 deletions
|
@ -376,7 +376,7 @@ prompt_aws() {
|
||||||
# Current Elastic Beanstalk environment
|
# Current Elastic Beanstalk environment
|
||||||
prompt_aws_eb_env() {
|
prompt_aws_eb_env() {
|
||||||
[[ -r .elasticbeanstalk/config.yml ]] || return
|
[[ -r .elasticbeanstalk/config.yml ]] || return
|
||||||
local v=${=$(grep environment .elasticbeanstalk/config.yml 2>/dev/null)[2]}
|
local v=${=$(command grep environment .elasticbeanstalk/config.yml 2>/dev/null)[2]}
|
||||||
[[ -n $v ]] && "$1_prompt_segment" "$0" "$2" black green 'AWS_EB_ICON' 0 '' "${v//\%/%%}"
|
[[ -n $v ]] && "$1_prompt_segment" "$0" "$2" black green 'AWS_EB_ICON' 0 '' "${v//\%/%%}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,7 +429,7 @@ 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() {
|
||||||
(( $+commands[df] )) || return
|
(( $+commands[df] )) || return
|
||||||
local disk_usage=${${=${(f)"$(command df -P .)"}[2]}[5]%%%}
|
local disk_usage=${${=${(f)"$(command df -P . 2>/dev/null)"}[2]}[5]%%%}
|
||||||
local state bg fg
|
local state bg fg
|
||||||
if (( disk_usage >= POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL )); then
|
if (( disk_usage >= POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL )); then
|
||||||
state=critical
|
state=critical
|
||||||
|
@ -476,7 +476,7 @@ prompt_battery() {
|
||||||
case $OS in
|
case $OS in
|
||||||
OSX)
|
OSX)
|
||||||
(( $+commands[pmset] )) || return
|
(( $+commands[pmset] )) || return
|
||||||
local raw_data=${${(f)$(command pmset -g batt)}[2]}
|
local raw_data=${${(f)$(command pmset -g batt 2>/dev/null)}[2]}
|
||||||
[[ $raw_data == *InternalBattery* ]] || return
|
[[ $raw_data == *InternalBattery* ]] || return
|
||||||
remain=${${(s: :)${${(s:; :)raw_data}[3]}}[1]}
|
remain=${${(s: :)${${(s:; :)raw_data}[3]}}[1]}
|
||||||
[[ $remain == *no* ]] && remain="..."
|
[[ $remain == *no* ]] && remain="..."
|
||||||
|
@ -991,13 +991,11 @@ prompt_history() {
|
||||||
################################################################
|
################################################################
|
||||||
# Detection for virtualization (systemd based systems only)
|
# Detection for virtualization (systemd based systems only)
|
||||||
prompt_detect_virt() {
|
prompt_detect_virt() {
|
||||||
local virt=$(systemd-detect-virt 2> /dev/null)
|
(( $+commands[systemd-detect-virt] )) || return
|
||||||
|
local virt=$(command systemd-detect-virt 2>/dev/null)
|
||||||
if [[ "$virt" == "none" ]]; then
|
if [[ "$virt" == "none" ]]; then
|
||||||
if [[ "$(ls -di / | grep -o 2)" != "2" ]]; then
|
[[ "$(command ls -di /)" != "2 /" ]] && virt="chroot"
|
||||||
virt="chroot"
|
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n "${virt}" ]]; then
|
if [[ -n "${virt}" ]]; then
|
||||||
"$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" '' 0 '' "${virt//\%/%%}"
|
"$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" '' 0 '' "${virt//\%/%%}"
|
||||||
fi
|
fi
|
||||||
|
@ -1066,7 +1064,7 @@ prompt_load() {
|
||||||
case $OS in
|
case $OS in
|
||||||
OSX|BSD)
|
OSX|BSD)
|
||||||
(( $+commands[sysctl] )) || return
|
(( $+commands[sysctl] )) || return
|
||||||
load=$(sysctl -n vm.loadavg) || return
|
load=$(command sysctl -n vm.loadavg 2>/dev/null) || return
|
||||||
load=${${(A)=load}[bucket+1]//,/.}
|
load=${${(A)=load}[bucket+1]//,/.}
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
@ -1077,9 +1075,9 @@ prompt_load() {
|
||||||
|
|
||||||
if (( ! $+_P9K_NUM_CPUS )); then
|
if (( ! $+_P9K_NUM_CPUS )); then
|
||||||
case $OS in
|
case $OS in
|
||||||
OSX) (( $+commands[sysctl] )) && _P9K_NUM_CPUS=$(sysctl -n hw.logicalcpu) || return;;
|
OSX) (( $+commands[sysctl] )) && _P9K_NUM_CPUS=$(command sysctl -n hw.logicalcpu 2>/dev/null) || return;;
|
||||||
BSD) (( $+commands[sysctl] )) && _P9K_NUM_CPUS=$(sysctl -n hw.ncpu) || return;;
|
BSD) (( $+commands[sysctl] )) && _P9K_NUM_CPUS=$(command sysctl -n hw.ncpu 2>/dev/null) || return;;
|
||||||
*) (( $+commands[nproc] )) && _P9K_NUM_CPUS=$(nproc) || return;;
|
*) (( $+commands[nproc] )) && _P9K_NUM_CPUS=$(command nproc 2>/dev/null) || return;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -1498,7 +1496,7 @@ prompt_swap() {
|
||||||
|
|
||||||
if [[ "$OS" == "OSX" ]]; then
|
if [[ "$OS" == "OSX" ]]; then
|
||||||
(( $+commands[sysctl] )) || return
|
(( $+commands[sysctl] )) || return
|
||||||
[[ "$(sysctl vm.swapusage)" =~ "used = ([0-9,.]+)([A-Z]+)" ]] || return
|
[[ "$(command sysctl vm.swapusage 2>/dev/null)" =~ "used = ([0-9,.]+)([A-Z]+)" ]] || return
|
||||||
used_bytes=${match[1]//,/.}
|
used_bytes=${match[1]//,/.}
|
||||||
case ${match[2]} in
|
case ${match[2]} in
|
||||||
K) (( used_bytes *= 1024 ));;
|
K) (( used_bytes *= 1024 ));;
|
||||||
|
@ -1508,7 +1506,7 @@ prompt_swap() {
|
||||||
*) return;;
|
*) return;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
local meminfo && meminfo=$(command grep -F 'Swap' /proc/meminfo) || return
|
local meminfo && meminfo=$(command grep -F 'Swap' /proc/meminfo 2>/dev/null) || return
|
||||||
[[ $meminfo =~ 'SwapTotal:[[:space:]]+([0-9]+)' ]] || return
|
[[ $meminfo =~ 'SwapTotal:[[:space:]]+([0-9]+)' ]] || return
|
||||||
(( used_bytes+=match[1] ))
|
(( used_bytes+=match[1] ))
|
||||||
[[ $meminfo =~ 'SwapFree:[[:space:]]+([0-9]+)' ]] || return
|
[[ $meminfo =~ 'SwapFree:[[:space:]]+([0-9]+)' ]] || return
|
||||||
|
@ -1575,7 +1573,6 @@ prompt_date() {
|
||||||
################################################################
|
################################################################
|
||||||
# todo.sh: shows the number of tasks in your todo.sh file
|
# todo.sh: shows the number of tasks in your todo.sh file
|
||||||
prompt_todo() {
|
prompt_todo() {
|
||||||
#emulate -L zsh && setopt xtrace
|
|
||||||
local todo=$commands[todo.sh]
|
local todo=$commands[todo.sh]
|
||||||
[[ -n $todo ]] || return
|
[[ -n $todo ]] || return
|
||||||
if (( ! $+_P9K_TODO_FILE )); then
|
if (( ! $+_P9K_TODO_FILE )); then
|
||||||
|
|
Loading…
Reference in a new issue