export ZSH_CONFIG=$HOME/.config/zsh

[[ -f "$ZSH_CONFIG/zsh-init.sh" ]] && source "$ZSH_CONFIG/zsh-init.sh"

source $OHMYZSH/oh-my-zsh.sh

command -v starship >/dev/null && eval "$(starship init zsh)" 2>/dev/null

# eza hyperlink workaround: oh-my-zsh's bare --hyperlink eats the next arg on newer eza.
_hl_flag="--hyperlink"
if command -v eza >/dev/null && eza --help 2>&1 | grep -q -- '--hyperlink.*<WHEN>'; then
  _hl_flag="--hyperlink=always"
fi
for _ea in la ldot lD lDD ll ls lsd lsdl lS lT; do
  (( $+aliases[$_ea] )) && alias "$_ea"="${aliases[$_ea]} $_hl_flag"
done
unset _ea _hl_flag

# zoxide: frecency-based directory jumping.
command -v zoxide >/dev/null && eval "$(zoxide init zsh)" 2>/dev/null

# bat: colored `cat` and colored man pages.
if command -v bat >/dev/null; then
  alias cat='bat'
  export BAT_THEME="${BAT_THEME:-Monokai Extended}"
  export MANPAGER="sh -c 'col -bx | bat -l man -p'"
  export MANROFFOPT='-c'
fi

# delta: prettier git diffs as git's pager.
command -v delta >/dev/null && export GIT_PAGER='delta'

alias c='clear'
alias q="exit"
alias usedev='use_dev_branch'
alias usemaster='use_master_branch'
alias nbstat=$'netbird status --json | jq -r \'.peers.details[]? | [(.hostname // .fqdn), .netbirdIp, .status] | @tsv\' | column -t -s $\'\\t\''   
alias open-ports="ss -tulpn | grep LISTEN"
alias yeet='yay -Rcs'

# Auto-update on interactive shell start. Disable with ZSHRC_UPDATE_DISABLED=true.
[[ -o interactive && "$ZSHRC_UPDATE_DISABLED" != "true" ]] && (( $+functions[update_zshrc] )) && update_zshrc

[[ -f $HOME/.zshrc.local ]] || touch $HOME/.zshrc.local
source $HOME/.zshrc.local

if [[ $FFENABLED != "false" && ( -o interactive || $(tty) == *"pts"* ) ]] && command -v fastfetch >/dev/null; then
  fastfetch --config examples/13
fi
