dotfiles/zshenv
Eryn Wells cbebbffee0 [zsh] Establish a DOTFILES_HOME variable
Look for a config file at ~/.config/dotfiles-home that contains the path to the
repo, or check the usual location of ~/.dotfiles.

Do this in a shell function in .zshenv so it's repeatable. This needs to be done
very early in the init process.
2026-01-18 08:05:33 -07:00

57 lines
1.3 KiB
Bash

# Eryn Wells <eryn@erynwells.me>
# Don't read global startup. It messes things up...
unsetopt GLOBAL_RCS
export SYS=`uname -s | tr A-Z a-z`
function init-env-dotfiles-path
{
local dotfiles_config="$HOME/.config/dotfiles-home"
if [[ -f "$dotfiles_config" ]]; then
export DOTFILES_HOME=$(cat "$dotfiles_config")
return
fi
if [[ -f "$HOME/.dotfiles/setup.sh" ]]; then
export DOTFILES_HOME="$HOME/.dotfiles"
return
fi
echo "WARNING: Couldn't find path to dotfiles" 1>&2
}
function init-env-fpath
{
local -r fpath_candidates=( \
"$HOME/.zsh/${SYS}-functions" \
"$HOME/.zsh/func" \
)
# Process the array in reverse order (`Oa` means "descending index order",
# in other worse "reverse order"; see PARAMETER EXPANSION section of the man
# pages) so the paths are prepended in the correct order.
for candidate in ${(Oa)fpath_candidates}; do
if [[ ! -d "$candidate" ]]; then
continue
fi
fpath=($candidate $fpath)
done
}
init-env-dotfiles-path
init-env-fpath
autoload -Uz do_init_functions
typeset -a zsh_init_env_functions=( \
init-env \
init-env-path \
init-env-tilde-paths \
init-env-python \
init-env-playdate \
init-env-vi \
init-env-$SYS \
)
do_init_functions zsh_init_env_functions