diff --git a/.zshrc b/.zshrc index d373ed5..c8d6b3c 100644 --- a/.zshrc +++ b/.zshrc @@ -40,6 +40,17 @@ source_file() { fi } +# Eval the output of a command, silently skipping if it fails or produces nothing +# Usage: eval_expr 'pyenv init -' +eval_expr() { + local cmd="$1" + local output + + if output="$(eval "$cmd" 2>/dev/null)" && [[ -n "$output" ]]; then + eval "$output" + fi +} + # ============================================================================= # PATH EXTENSIONS @@ -90,9 +101,7 @@ eval_expressions=( ) for expr in "${eval_expressions[@]}"; do - if output="$(eval "$expr" 2>/dev/null)"; then - eval "$output" - fi + eval_expr "$expr" done