#!/bin/bash

set -eu
set -o pipefail

if type gtar > /dev/null 2>&1
then
    tar=gtar
else
    tar=tar
fi

find='find'
for candidate_find in /usr/bin/find /bin/find /usr/bin/find.exe /bin/find.exe
do
    if [ -f "$candidate_find" ]
    then
        find="$candidate_find"
        break
    fi
done

function opsys
{
    uname -s | tr '[:upper:]' '[:lower:]'
}

case "$(opsys)" in
    msys*)
        # shellcheck disable=SC2016
        hohm=$(powershell 'echo $HOME')
        vimrc=_vimrc
        ;;
    *)
        hohm=$HOME
        vimrc=.vimrc
        ;;
esac

# Hypothesis: This contains nvim packages that we reinstall each time we run this script.
rm -rf "$hohm"/.local/share/nvim

rm -rf "$hohm"/.config/nvim

# BTW, if you have a vim setting that's not what you want (EG Cylance tabstops being 8 instead of 4), you can:
# :verbose set tabstop?
# ...to see where it's getting set.

(
    set -eu
    cd hierarchy
    # shellcheck disable=SC2086
    $find . \
        \( \
            -name .svn \
        \) -prune -o \( -type f -o -type l \) -print | \
        $tar --create --no-recursion --file - --files-from - | \
        (cd "$hohm" && "$tar" xvfp -) || true
)

# Despite this, we'll probably use pyright.
./install-via-pip \
    --python-path "$(which python3)" \
    --module-to-import pylsp \
    --pip-package 'python-lsp-server[mccabe,pycodestyle,pydocstyle,rope,yapf]'

git \
	clone \
	--depth 1 \
	https://github.com/wbthomason/packer.nvim \
	"$hohm"/.local/share/nvim/site/pack/packer/start/packer.nvim

./os-packages