diff options
author | John Koelndorfer <jkoelndorfer@gmail.com> | 2015-09-02 01:18:09 +0300 |
---|---|---|
committer | John Koelndorfer <jkoelndorfer@gmail.com> | 2015-09-02 02:40:11 +0300 |
commit | f42242d34cfdb106be4ab16736b1ec4aa4bdbbed (patch) | |
tree | faa4fb05343cd60107fa0ed7d1eb3139388e1136 | |
parent | bf9ef6acf179015e422cc29a1d85799e48e1c93d (diff) |
Implement defined, set_default functions.
-rw-r--r-- | powerlevel9k.zsh-theme | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 56ecb611..ec8a859a 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -48,6 +48,14 @@ # Utility functions ################################################################ +# 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 +} + function print_icon() { local icon_name=$1 local ICON_USER_VARIABLE=POWERLEVEL9K_${icon_name} @@ -59,6 +67,18 @@ function print_icon() { fi } +# Given the name of a variable and a default value, sets the variable +# value to the default only if it has not been defined. +# +# typeset cannot set the value for an array, so this will only work +# for scalar values. +function set_default() { + local varname="$1" + local default_value="$2" + + defined "$varname" || typeset -g "$varname"="$default_value" +} + ################################################################ # Icons ################################################################ |