#!/usr/bin/env zsh

# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
export XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
export XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache}
export XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
export XDG_STATE_HOME=${XDG_STATE_HOME:-$HOME/.local/state}
export XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-$HOME/.xdg}

for xdgdir in XDG_{CONFIG,CACHE,DATA,STATE}_HOME XDG_RUNTIME_DIR; do
  [[ -e ${(P)xdgdir} ]] || mkdir -p ${(P)xdgdir}
done

# Ensure path arrays do not contain duplicates.
typeset -gU path fpath cdpath

fpath=(
  ${ZDOTDIR:-${XDG_CONFIG_HOME:-$HOME/.config}/zsh}/completions(-/FN)

  $fpath
)

path=(
  $HOME/{,.local/,.dotfiles/}{,s}bin(N)

  $HOME/.{go,cargo,pyenv,pixi,bun,nimble}/bin(N)
  $HOME/.zig/(N)

  /{opt,usr}/{,local/}{,s}bin(N)

  # prefer NixOs paths to qtile path corruption
  /run/{wrappers,current-system/sw}/bin(N)

  $path
)

for rcfile in $ZDOTDIR/local/{current,shared}/*.{,z}sh(N); do
  source $rcfile
done

export LESS="${LESS:--g -i -M -R -S -w -z-4}"
# Use `< file` to quickly view the contents of any file.
[[ -z "$READNULLCMD" ]] || READNULLCMD=$PAGER

# needed for omz plugin colored-man-pages
autoload colors && colors