#!/usr/bin/env bash

# omarchy:summary=Install the zsh shell environment: starship, direnv, fzf, bat, eza, btop, tldr, delta and gum, with zsh as the login shell
# omarchy:requires-sudo=true

# Based: the tools from apt or brew. On Debian the zsh dotfiles ship in
# based-shell-config, which seeds new and existing homes; a Mac gets the
# tools and keeps its own dotfiles.

set -eo pipefail

echo "Installing the shell environment..."
omarchy-pkg-add zsh linux=only based-shell-config linux=only direnv starship fortune-mod brew=fortune \
  fortunes linux=only fortunes-min linux=only fortunes-bofh-excuses linux=only cowsay lolcat bat fzf eza btop \
  tldr brew=tlrc git-delta gum

if omarchy-cmd-present batcat && omarchy-cmd-missing bat; then
  mkdir -p ~/.local/bin
  ln -sf /usr/bin/batcat ~/.local/bin/bat
fi

current_shell=$(getent passwd "$USER" 2>/dev/null | cut -d: -f7 || true)
[[ -n $current_shell ]] || current_shell=$SHELL
case $current_shell in
*zsh) ;;
*)
  echo "Making zsh the login shell..."
  if [[ $(omarchy-os) == darwin ]]; then
    chsh -s /bin/zsh
  else
    sudo usermod -s /usr/bin/zsh "$USER"
  fi
  ;;
esac
