#!/bin/zsh
# Setup PATH and MANPATH. In its own file because on macOS it has to be sourced
# twice for both non-interactive and interactive shells due to the OS adjusting
# PATH between .zshenv and .zshrc.

typeset -U path
typeset -U manpath

function prepend_to_path_if_exists() {
	local path_entry=$1
	if [[ -d "$path_entry" ]]; then
		path=("$path_entry" $path)
	fi
}

function prepend_to_manpath_if_exists() {
	local path_entry=$1
	if [[ -d "$path_entry" ]]; then
		manpath=("$path_entry" $manpath)
	fi
}

prepend_to_path_if_exists /usr/local/texlive/2023basic/bin/universal-darwin
prepend_to_path_if_exists /usr/lib/ccache
prepend_to_path_if_exists /usr/local/bin
prepend_to_path_if_exists /usr/local/sbin
prepend_to_path_if_exists /opt/homebrew/opt/bison/bin
prepend_to_path_if_exists /opt/homebrew/bin
prepend_to_path_if_exists ~/.asdf/shims

prepend_to_path_if_exists /opt/homebrew/opt/coreutils/libexec/gnubin/
prepend_to_manpath_if_exists /opt/homebrew/opt/coreutils/libexec/gnuman/

prepend_to_path_if_exists /opt/homebrew/opt/gnu-sed/libexec/gnubin/
prepend_to_manpath_if_exists /opt/homebrew/opt/gnu-sed/libexec/gnuman/

prepend_to_path_if_exists ~/.local/bin

prepend_to_path_if_exists ~/usr/bin
