#!/usr/bin/env bash

GIT_DOMAIN=https://git.puffypony.party:4433

NOW=$(pwd)

# Setup git
git config --global user.email "9hmbzr275@mozmail.com"
git config --global user.name "Segcolt"
git config --global core.editor "nvim"

# Clone some configs
git clone $GIT_DOMAIN/Segcolt/kitty-conf $HOME/.config/kitty
git clone $GIT_DOMAIN/Segcolt/astronvim-config $HOME/.config/nvim

# Clone and install Ascii-Pony
git clone https://gitlab.com/mattia.basaglia/ASCII-Pony pony
make PREFIX=$HOME/.local -C pony install

# Download and install kitty terminal
curl -L https://sw.kovidgoyal.net/kitty/installer.sh | sh /dev/stdin \
    launch=n
ln -s $HOME/.local/kitty.app/bin/kitty $HOME/.local/bin/kitty
ln -s $HOME/.local/kitty.app/bin/kitten $HOME/.local/bin/kitten
ln -s $HOME/.local/kitty.app/share/applications/kitty.desktop $HOME/.local/share/applications/kitty.desktop
sed -i -e 's/JetBrains Mono/Monocraft Nerd Font/' $HOME/.config/kitty/kitty.conf
    
#Setup flatpak
flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

# Setup vim appimage
chmod +x nvim.appimage
mv nvim.appimage $HOME/.local/bin/nvim

# Install clangd
readonly CLANGD_VER=19.1.0
mkdir $HOME/.config/clangd
mv clangd/clangd/config.yaml $HOME/.config/clangd
curl -SL https://github.com/clangd/clangd/releases/download/${CLANGD_VER}/clangd-linux-${CLANGD_VER}.zip > clangd.zip
unzip clangd.zip
mv clangd_${CLANGD_VER}/bin/clangd $HOME/.local/bin
mv clangd_${CLANGD_VER}/lib/clang $HOME/.local/lib

# Download and install cmake
readonly CMAKE_VER_LONG="3.30.3"
readonly CMAKE_VER_SHORT="3.30"
curl -L https://github.com/Kitware/CMake/releases/download/v3.30.3/cmake-${CMAKE_VER_LONG}-linux-x86_64.tar.gz > cmake.tar.gz
tar xvzf cmake.tar.gz
mv cmake-${CMAKE_VER_LONG}-linux-x86_64/bin/* $HOME/.local/bin
mv cmake-${CMAKE_VER_LONG}-linux-x86_64/share/cmake-${CMAKE_VER_SHORT} $HOME/.local/share/cmake-${CMAKE_VER_SHORT}
export CMAKE_ROOT="$HOME/.local/share/cmake-${CMAKE_VER_SHORT}"

# Setup fonts
mkdir -p $HOME/.local/share/fonts
mv fonts/* $HOME/.local/share/fonts
curl -L https://github.com/IdreesInc/Monocraft/releases/download/v4.0/Monocraft-nerd-fonts-patched.ttc > $HOME/.local/share/fonts/Monocraft.ttc
fc-cache -fv

# Install all neovim plugins from config
nvim

# Download and install luajit
git clone https://luajit.org/git/luajit.git 
cd luajit
make
make install PREFIX=$HOME/.local

# Setup neoclip
cd $HOME/.local/share/nvim/lazy/neoclip/src
CMAKE_PREFIX_PATH=$HOME/.local cmake -B build && make -C build && make -C build install
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/.local/lib

# Put some alias and variables into .bashrc
echo "export LD_LIBRARY_PATH='$HOME/.local/lib'" >> $HOME/.bashrc
echo "alias compile='g++ -O0 -g -fsanitize=address -o fds -std=c++17'" >> $HOME/.bashrc

# Install and setup fish
cd "$NOW"
./fish_shell_install.sh
rm -rf $HOME/.config/fish
git clone -b alternative $GIT_DOMAIN/Segcolt/fish-config $HOME/.config/fish

# Install and setup fzf
readonly FZF_VER=0.55.0
curl -sSL https://github.com/junegunn/fzf/releases/download/v${FZF_VER}/fzf-${FZF_VER}-linux_amd64.tar.gz > fzf.tar.gz
tar xvzf fzf.tar.gz -C $HOME/.local/bin

# Install and setup starship
curl -sS https://starship.rs/install.sh | sh -s -- --bin-dir $HOME/.local/bin
curl -sSL https://raw.githubusercontent.com/catppuccin/starship/refs/heads/main/starship.toml > $HOME/.config/starship.toml
sed -i '0,/catppuccin_macchiato/s//catppuccin_mocha/' $HOME/.config/starship.toml

# Download and install qalc
QALC_VER=5.2.0
curl -sSL https://github.com/Qalculate/libqalculate/releases/download/v${QALC_VER}/qalculate-${QALC_VER}-x86_64.tar.xz > qalc.tar.xz
tar xvJf qalc.tar.xz
mv qalculate-${QALC_VER}/qalc $HOME/.local/bin
