summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Hilburn <bhilburn@gmail.com>2018-07-13 20:25:45 +0300
committerGitHub <noreply@github.com>2018-07-13 20:25:45 +0300
commita7b3f310d3c1e5306332dd15401efb9631c76bed (patch)
treef86464cadab0cfa107e9137d0141a4511de2db77
parente1a420b5d20b11da108b202eb7020437869a28a8 (diff)
parent45b0d68ec435a89ccc13193149a5bc306d449d04 (diff)
Merge pull request #905 from robobenklein/robobenklein/defined-variable-performance-hotfix
[performance] Defined function 2-20 times speedup
-rwxr-xr-xfunctions/utilities.zsh4
-rwxr-xr-xpowerlevel9k.zsh-theme2
2 files changed, 2 insertions, 4 deletions
diff --git a/functions/utilities.zsh b/functions/utilities.zsh
index 69fd2ec8..127007fb 100755
--- a/functions/utilities.zsh
+++ b/functions/utilities.zsh
@@ -9,9 +9,7 @@
# Exits with 0 if a variable has been previously defined (even if empty)
# Takes the name of a variable that should be checked.
function defined() {
- local varname="$1"
-
- typeset -p "$varname" > /dev/null 2>&1
+ [[ ! -z "${(tP)1}" ]]
}
# Given the name of a variable and a default value, sets the variable
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index ab56d234..f3126b81 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -498,7 +498,7 @@ prompt_battery() {
fi
fi
# return if POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD is set and the battery percentage is greater or equal
- if [[ -v "POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD" && "${bat_percent}" -ge $POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD ]]; then
+ if defined POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD && [[ "${bat_percent}" -ge $POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD ]]; then
return
fi