[zsh] Process fpath candidate paths in a loop in init-env-fpath

This commit is contained in:
Eryn Wells 2024-09-26 10:06:20 -07:00
parent 80e2915b89
commit a026b9c8a9

19
zshenv
View file

@ -7,15 +7,20 @@ export SYS=`uname -s | tr A-Z a-z`
function init-env-fpath function init-env-fpath
{ {
local user_fpath=("$HOME/.zsh/func") local -r fpath_candidates=( \
"$HOME/.zsh/${SYS}-functions" \
"$HOME/.zsh/func" \
)
local sys_fpath="$HOME/.zsh/func/$SYS" # Process the array in reverse order (`Oa` means "descending index order",
if [[ -d "$sys_fpath" ]]; then # in other worse "reverse order"; see PARAMETER EXPANSION section of the man
user_fpath+=($sys_fpath) # pages) so the paths are prepended in the correct order.
for candidate in ${(Oa)fpath_candidates}; do
if [[ ! -d "$candidate" ]]; then
continue
fi fi
fpath=($candidate $fpath)
fpath=($user_fpath $fpath) done
export FPATH
} }
init-env-fpath init-env-fpath