From 55575b88f9e47d88fab02c26fc69e4af48af1cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Mon, 25 Feb 2019 23:20:47 +0100 Subject: [PATCH] lib: optimize default and env_default --- lib/functions.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/functions.zsh b/lib/functions.zsh index 4ef8920f6..9f8736bd7 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -79,7 +79,7 @@ function try_alias_value() { # 0 if the variable exists, 3 if it was set # function default() { - test `typeset +m "$1"` && return 0 + (( $+parameters[$1] )) && return 0 typeset -g "$1"="$2" && return 3 } @@ -93,8 +93,8 @@ function default() { # 0 if the env variable exists, 3 if it was set # function env_default() { - env | grep -q "^$1=" && return 0 - export "$1=$2" && return 3 + (( ${${(@f):-$(typeset +xg)}[(I)$1]} )) && return 0 + export "$1=$2" && return 3 }