Commit 55575b88 authored by Marc Cornellà's avatar Marc Cornellà
Browse files

lib: optimize default and env_default

parent 4cdffcd4
...@@ -79,7 +79,7 @@ function try_alias_value() { ...@@ -79,7 +79,7 @@ function try_alias_value() {
# 0 if the variable exists, 3 if it was set # 0 if the variable exists, 3 if it was set
# #
function default() { function default() {
test `typeset +m "$1"` && return 0 (( $+parameters[$1] )) && return 0
typeset -g "$1"="$2" && return 3 typeset -g "$1"="$2" && return 3
} }
...@@ -93,7 +93,7 @@ function default() { ...@@ -93,7 +93,7 @@ function default() {
# 0 if the env variable exists, 3 if it was set # 0 if the env variable exists, 3 if it was set
# #
function env_default() { function env_default() {
env | grep -q "^$1=" && return 0 (( ${${(@f):-$(typeset +xg)}[(I)$1]} )) && return 0
export "$1=$2" && return 3 export "$1=$2" && return 3
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment