#!/usr/bin/env bash

function upsert_dir_symlink() {
  local from="$1"
  local to="$2"
  { [ -d "$to" ] || [ -L "$to" ]; } || {
    ln -s "$from" "$to"
  }
}
export -f upsert_dir_symlink

upsert_dir_symlink "$HOME/dev/libre/others/borg/config" ~/.config/borg

ln -fs "$DOTFILES/bash/bashrc.sh"               ~/.bashrc
ln -fs "$DOTFILES/bash/bash_profile.sh"         ~/.bash_profile
ln -fs "$DOTFILES/git/gitattributes"            ~/.gitattributes
ln -fs "$DOTFILES/git/gitignore"                ~/.gitignore_global
ln -fs "$DOTFILES/git/gitconfig.ini"            ~/.gitconfig
ln -fs "$DOTFILES/sbclrc.lisp"                  ~/.sbclrc
ln -fs "$DOTFILES/inputrc.conf"                 ~/.inputrc
ln -fs "$DOTFILES/Xmodmap.conf"                 ~/.Xmodmap
ln -fs "$DOTFILES/nixos/npmrc.sh"             ~/.npmrc

mkdir -p ~/.gnupg
ln -fs "${HOME}/annex/bin/misc/gpg/gpg.conf"       ~/.gnupg/gpg.conf
ln -fs "${HOME}/annex/bin/misc/gpg/gpg-agent.conf" ~/.gnupg/gpg-agent.conf
ln -fs "${HOME}/annex/bin/misc/git/mrconfig.ini"   ~/.mrconfig

mkdir -p ~/.newsboat
ln -fs "${HOME}/annex/bin/misc/atom/newsboat-urls.txt" ~/.newsboat/urls

MEDIA_PREFIX=/run/media/andreh
upsert_dir_symlink "$MEDIA_PREFIX/UTCLOUD"      ~/UTCLOUD
upsert_dir_symlink "$MEDIA_PREFIX/SNEAKER"     ~/SNEAKER

## tmux
ln -fs "$DOTFILES/tmux/tmux.conf"               ~/.tmux.conf
ln -fs "$DOTFILES/tmux/tmux-macos.conf"         ~/.tmux-macos.conf
ln -fs "$DOTFILES/tmux/tmux-gnu-linux.conf"     ~/.tmux-gnu-linux.conf

## Emacs
mkdir -p "$HOME/.emacs.d/private/layers/"
ln -fs "$DOTFILES/spacemacs.el"                 ~/.spacemacs

## xmonad
mkdir -p ~/.xmonad
ln -fs "$DOTFILES/xmonad/xsession.sh"           ~/.xsession
ln -fs "$DOTFILES/xmonad/xmonad.hs"             ~/.xmonad/xmonad.hs
ln -fs "$DOTFILES/xmonad/xmobar.hs"             ~/.xmobarrc

## Mercurial
ln -fs "${DOTFILES}/mercurial/hgrc.ini"         ~/.hgrc

## ranger
mkdir -p ~/.config/ranger/
ln -fs "${DOTFILES}/ranger.conf"                ~/.config/ranger/rc.conf

## Vim
ln -fs "${DOTFILES}/vimrc.conf"                 ~/.vimrc

## nu
ln -fs "$HOME/annex/bin/misc/nurc.sh"           ~/.nurc

## Guix
ln -fs "$DOTFILES/guix/channels.scm"            ~/.config/guix/channels.scm
