#!/usr/bin/env sh

# shellcheck disable=SC2034

set -e
set -ux

zshdest="${HOME}/.config/zsh/completions"
bashdest="${HOME}/.local/share/bash-completion"
xbindest="${HOME}/.local/bin"
cheatsdest="${HOME}/.dotfiles/cheats"
mandest="${HOME}/.local/share/man/man1"

run() {
  echo '$' "$@"
  "$@"
}

make_dir() {
  run mkdir -p "$1"
}

## bash-preexec.sh
# bshprxcurl=https://raw.githubusercontent.com/rcaloras/bash-preexec/refs/heads/master
# curl -fsSL "$bshprxcurl"/bash-preexec.sh -o "${xbindest}"/bash-preexec.sh

## clitest
# clitestreadmeurl=https://raw.githubusercontent.com/aureliojargas/clitest/refs/heads/main
# clitesturl=https://raw.github.com/aureliojargas/clitest/master
# curl -fsSL "$clitesturl"/clitest -o "${xbindest}"/clitest
# curl -fsSL "$clitestreadmeurl"/README.md -o "${cheatsdest}"/clitest.md

## fzf-note
# fzfnoteurl=https://gist.githubusercontent.com/junegunn/402e3d19271bc68de59ce34eb7dc6ae5/raw/50b6f20754b722777b7c741be1d0fef701caadf5
# curl -fsSL "${fzfnoteurl}"/notes.sh -o "${xbindest}"/note

## fzf-git
# fzfgiturl=https://raw.githubusercontent.com/junegunn/fzf-git.sh/main
# curl -fsSL "${fzfgiturl}"/fzf-git.sh -o "${xbindest}"/fzf-git.sh

## git-cloner
# gitclonerurl=https://raw.githubusercontent.com/mattmc3/dotfiles/refs/heads/main/bin
# curl -fsSL "$gitclonerurl"/git-cloner -o "${xbindest}"/git-cloner

## git-repl - https://github.com/tj/git-extras
# gitreplurl=https://raw.githubusercontent.com/tj/git-extras/refs/heads/main/bin
# curl -fsSL "${gitreplurl}"/git-repl -o "${xbindest}"/git-repl

## hgrep
# if command -v hgrep >/dev/null 2>&1; then
#   hgrep --generate-man-page >"${mandest-}"/hgrep.1
# fi

## imgcat - https://iterm2.com/documentation-images.html
## https://iterm2.com/utilities/imgcat
# wget -O- "https://iterm2.com/utilities/imgcat" > "${xbindest}"/imgcat &&
#   chmod a+x "${xbindest}"/imgcat
# imgcaturl=https://raw.githubusercontent.com/gnachman/iTerm2-shell-integration/refs/heads/main/utilities
# imgcaturl=https://iterm2.com/utilities
# curl -fsSL "${imgcaturl}"/imgcat -o "${xbindest}"/imgcat

## listening.py - https://github.com/cdzombak/listening
# listeningurl=https://raw.githubusercontent.com/cdzombak/listening/refs/heads/main
# curl -fsSL "${listeningurl}"/listening.py -o "${xbindest}"/listening.py

## llmcat - https://github.com/azer/llmcat
# llmcaturl=https://raw.githubusercontent.com/azer/llmcat/refs/heads/main
# curl -fsSL "${llmcaturl}"/llmcat -o "${xbindest}"/llmcat

## notes - https://github.com/pimterry/notes
# notesurl=https://raw.githubusercontent.com/pimterry/notes/latest-release
# curl -fsSL "${notesurl}"/notes -o "${xbindest}"/notes
# notesurl=https://raw.githubusercontent.com/pimterry/notes/refs/heads/master
# curl -fsSL "${notesurl}"/notes -o "${xbindest}"/notes

## pipestatus - https://github.com/ko1nksm/sh-pipestatus
# pipesurl=https://raw.githubusercontent.com/ko1nksm/sh-pipestatus/refs/heads/main
# curl -fsSL "${pipesurl}"/pipestatus.sh -o "${xbindest}"/pipestatus

## retronews.py
# if command -v retronews >/dev/null 2>&1; then
#   retronurl=https://raw.githubusercontent.com/luke8086/retronews/refs/heads/main
#   curl -fsSL "${retronurl}"/retronews.py -o "${xbindest}"/retronews.py
# fi

## shell-safe-rm
# safermurl=https://raw.githubusercontent.com/kaelzhang/shell-safe-rm/refs/heads/master/bin
# curl -fsSL "$safermurl"/rm.sh -o "${xbindest}"/shell-safe-rm

## shellcheck-wiki | git clone git@github.com:koalaman/shellcheck.wiki.git
# r="${TMPDIR:-/tmp}/workspaces/$(xxd -l3 -ps /dev/urandom)"
# mkdir -p "${r}" && cd "${r}" || exit
# git clone https://github.com/koalaman/shellcheck.wiki.git
# cd "${r}/shellcheck.wiki" || exit
# head -n 1 SC*.md \
# | perl -p -e 's/\n//g;s/==>/\n/g;' \
# | perl -p -e 's!^\s*(SC\d+)\s*[.]md\s*<==(##)?(\s|#)*![$1](https://github.com/koalaman/shellcheck/wiki/$1) !' >shellcheck-wiki.md
# command mv -f "${r}"/shellcheck.wiki/shellcheck-wiki.md "${cheatsdest}"/shellcheck-wiki.md

## ssh.py
# spyurl=https://raw.githubusercontent.com/azlux/ssh-prompter/0536b91e5a2c126930abf4e01f15f9db30883639
# curl -fsSL "${spyurl}"/ssh.py -o "${xbindest}"/ssh.py

## str
# strurl=https://raw.githubusercontent.com/mattmc3/dotfiles/refs/heads/main/bin
# curl -fsSL "$strurl"/str -o "${xbindest}"/str

## terminal-colors
# tcolorsurl=https://raw.githubusercontent.com/eikenb/terminal-colors/master
# curl -fsSL "$tcolorsurl"/terminal-colors -o "${xbindest}"/terminal-colors

## todo - https://git.sr.ht/~xan/todo-cli
# todourl=https://git.sr.ht/~xan/todo-cli/blob/main
# curl -fsSL "${todourl}"/todo -o "${xbindest}"/todo
# curl -fsSL "${todourl}"/contrib/completions/todo.bash -o "${bashdest}"/todo
# curl -fsSL "${todourl}"/todo.1 -o "${mandest}"/todo.1

## tzdiff
# tzdurl=https://raw.githubusercontent.com/belgianbeer/tzdiff/refs/heads/main
# curl -fsSL "${tzdurl}"/tzdiff -o "${xbindest}"/tzdiff
# curl -fsSL "${tzdurl}"/tzdiff.1 -o "${mandest}"/tzdiff.1

## yt-x
# curl -sL "https://raw.githubusercontent.com/Benexl/yt-x/refs/heads/master/yt-x" -o ~/.local/bin/yt-x && chmod +x ~/.local/bin/yt-x

## yubikey-guide
# https://github.com/drduh/YubiKey-Guide/blob/master/README.md
# curl -sSfL https://raw.githubusercontent.com/drduh/YubiKey-Guide/refs/heads/master/README.md -o ~/.dotfiles/cheats/yubikey-guide.md

## zsh-manpage-completion-generator
# curl -sSfL https://raw.githubusercontent.com/fish-shell/fish-shell/refs/heads/master/share/tools/create_manpage_completions.py -o ~/.local/bin/create_manpage_completions.py
# curl -sSfL https://raw.githubusercontent.com/fish-shell/fish-shell/refs/heads/master/share/tools/deroff.py -o ~/.local/bin/deroff.py
# chmod +x ~/.local/bin/create_manpage_completions.py
# chmod +x ~/.local/bin/deroff.py

## macos/linux
# if [ -d "${HOME}"/.dotfiles/gdb/.config/gdb ]; then
#   gdbdest=${HOME}/.dotfiles/gdb/.config/gdb
#   gdbiniturl=https://raw.githubusercontent.com/gdbinit/Gdbinit/refs/heads/master
#   curl -fsSL "${gdbiniturl}"/gdbinit -o "${gdbdest}"/gdbinit
# fi

## linux
# if [ -d "${HOME}"/.dotfiles/os/linux/etc/cron.d ]; then
#   cronddest=${HOME}/.dotfiles/os/linux/etc/cron.d
#   # wifi-check-script.sh wifi-check-script.cron
#   wificheckurl=https://raw.githubusercontent.com/cdzombak/dotfiles/refs/heads/master/linux/pi
#   curl -fsSL "${wificheckurl}"/wifi-check.sh -o "${cronddest}"/wifi-check-script.sh
#   curl -fsSL "${wificheckurl}"/wifi-check.cron -o "${cronddest}"/wifi-check-script.cron
# fi

{
  set +ux
} 2>/dev/null
