From 4270c8bf7290864bd0e4400557207f6962b37de3 Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Wed, 11 Apr 2012 20:51:10 -0400 Subject: [PATCH] Fix z sourcing --- modules/z/init.zsh | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/modules/z/init.zsh b/modules/z/init.zsh index b3d1e28..2fc82c9 100644 --- a/modules/z/init.zsh +++ b/modules/z/init.zsh @@ -5,13 +5,23 @@ # Sorin Ionescu # -if [[ -f /etc/profile.d/z.zsh ]]; then - source /etc/profile.d/z.zsh -elif [[ -f /opt/local/etc/profile.d/z.zsh ]]; then - source /opt/local/etc/profile.d/z.zsh -elif [[ -f "$(brew --prefix 2> /dev/null)/etc/profile.d/z.sh" ]]; then - source "$(brew --prefix 2> /dev/null)/etc/profile.d/z.sh" -fi +_z_prefixes=( + '' + '/usr/local' + '/opt/local' + "$(brew --prefix 2> /dev/null)" +) + +for _z_prefix in "$_z_prefixes[@]"; do + _z_sh="${_z_prefix}/etc/profile.d/z.sh" + + if [[ -f "$_z_sh" ]]; then + source "$_z_sh" + break + fi +done + +unset _z_prefix{es,} _z_sh if (( $+functions[_z] )); then alias z='nocorrect _z 2>&1'