#!/bin/bash

PATH_PREFIX=`pwd`

rm -r ~/.config/htop
ln -s $PATH_PREFIX/config/htop ~/.config/htop

rm ~/.gitconfig
ln -s $PATH_PREFIX/gitconfig ~/.gitconfig

rm ~/.nanorc
ln -s $PATH_PREFIX/nanorc ~/.nanorc

rm ~/.p10k.zsh
ln -s $PATH_PREFIX/p10k.zsh ~/.p10k.zsh

rm ~/.tmux.conf
ln -s $PATH_PREFIX/tmux.conf ~/.tmux.conf

rm ~/.zshrc
ln -s $PATH_PREFIX/zshrc ~/.zshrc

rm ~/.fzf.zsh
ln -s $PATH_PREFIX/fzf.zsh ~/.fzf.zsh

rm -r ~/.config/lf
ln -s $PATH_PREFIX/config/lf ~/.config/lf

# get tmux plugin manager going if needed
if ! ( [ -d ~/.tmux -a -d ~/.tmux/plugins -a -d ~/.tmux/plugins/tpm ] ); then
    mkdir -p ~/.tmux/plugins/tpm
    git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
fi

# get asdf going if needed
if ! [ -d ~/.asdf ]; then
    git clone https://github.com/asdf-vm/asdf.git ~/.asdf
    cd ~/.asdf
    git checkout `git describe --tags --abbrev=0`
    cd $PATH_PREFIX
fi

# fonts
if ! [ -d ~/.fonts ]; then
    mkdir ~/.fonts
fi
cp $PATH_PREFIX/fonts/* ~/.fonts/

# termux tuning
if grep -q "Android" <<< `uname -a`; then
    # grab always run in background permission during early setup
    termux-wake-lock
    termux-wake-unlock
    if ! [ -d ~/.termux ]; then
        mkdir ~/.termux
    fi
    rm ~/.termux/termux.properties
    # must be copy to prevent error on termux startup
    cp $PATH_PREFIX/termux/termux.properties ~/.termux/termux.properties
    # shortcuts
    if ! [ -d ~/.shortcuts ]; then
        mkdir ~/.shortcuts
    fi
    # cannot use symlinks -- termux forces full path execution from android launcher shortcuts
    cp $PATH_PREFIX/shortcuts/* ~/.shortcuts/
    # reload settings
    termux-reload-settings
fi

echo "exa fd bat tmux htop nano most ripgrep emacs zsh lf restic rclone glow"
echo "termux-api"
echo "copy restic.sh if desired/needed"
echo "setup rclone for org/nextcloud sync if necessary (use 'nc-personal' for destination name)"
echo "run tmux and do <prefix>-I to install plugins and finish setup"
