#!/bin/sh

die() {
	printf "\33[2K\r\033[1;31m%s\033[0m\n" "$*" >&2
	exit 1
}

trap "exit 1" INT HUP

#check your os
case $(uname -o) in
	*ndroid*) 	#termux
		install_dir="$HOME/.shortcuts"
		pkg_mgr="pkg in -y"
		pkg_upd="pkg up -y"
		pkg_spec="openssl-tool"
		gh_user="https://github.com/"
		;;
	*)	#arch linux
		pkg_mgr="doas pacman -S --needed --no-confirm"
		pkg_upd="doas pacman -Syyu"
		pkg_spec="mpv bemenu-wayland"
		command -v doas >/dev/null || die "Please install doas!!!"
		gh_user="git@github.com:"
		;;
esac

#updating system
$pkg_upd

#installing git
$pkg_mgr git

#cloning repo
git clone ${gh_user}coolnsx/repos_scripts $install_dir

#installing common pkgs
$pkg_mgr aria2 fzf ffmpeg python python-pip ncurses starship

#installing os-specific pkgs
$pkg_mgr $pkg_spec

if [ -n "$install_dir" ]; then
	[ -d "$HOME/.config" ] || mkdir "$HOME/.config"
	git clone "https://github.com/zsh-users/zsh-syntax-highlighting" "$HOME/.config/zsh-syntax"
	curl -s "https://raw.githubusercontent.com/CoolnsX/hyprdots/master/zsh/zshrc" | sed '$d' > $HOME/.zshrc
	printf 'source $HOME/.config/zsh-syntax/zsh-syntax-highlighting.zsh' >> $HOME/.zshrc
fi
