This repository has been archived on 2024-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/setup

94 lines
2.7 KiB
Bash
Executable file

#!/usr/bin/env bash
if [[ -z "$XDG_CONFIG_HOME" ]]; then
export XDG_CONFIG_HOME="$HOME/.config"
fi
dfp=$(cd "$(dirname "${BASH_SOURCE[0]}" )/" && pwd)
ALERT_AGREEMENT_FILE="$dfp/.agreed-to-erasing-files.lock"
# Let user know that this script will delete their current configuration and
# that they should read this script before running. We'll use a lock file so
# the user only needs to agree once.
if [ -f "$ALERT_AGREEMENT_FILE" ]; then
# User agreed already - do nothing
echo "Linking..."
else
echo "Running this script may delete existing personal configuration files."
echo "Please view this script's source, fully understand it, and backup any"
echo "files before continuing."
echo "Seriously. Like... entire directories. Just gone."
read -r -p "Are you sure you want to continue? [y/N] " response
response=${response,,} # to lower case
if [[ $response =~ ^(yes|y)$ ]]; then
echo "agreed" > "$ALERT_AGREEMENT_FILE"
else
exit 1
fi
fi
# TODO: make sure we have an even number, here
links=(
# desktop environment files
"$dfp/de/bspwmrc" "$XDG_CONFIG_HOME/bspwm/bspwmrc"
"$dfp/de/sxhkdrc" "$XDG_CONFIG_HOME/sxhkd/sxhkdrc"
"$dfp/de/xresources" "$HOME/.Xresources"
"$dfp/de/xinitrc" "$HOME/.xinitrc"
"$dfp/de/xprofile" "$HOME/.xprofile"
"$dfp/common/colors/xresources" "$HOME/.Xresources.colors"
# bar files
"$dfp/de/bar/polybar-config" "$XDG_CONFIG_HOME/polybar/config"
# shell files
"$dfp/shell/bashrc" "$HOME/.bashrc"
"$dfp/shell/bash_profile" "$HOME/.bash_profile"
"$dfp/shell/tmux.conf" "$HOME/.tmux.conf"
"$dfp/shell/tmux-layouts" "$HOME/.tmux/layouts"
# text editor files
"$dfp/text-editor/neovim/" "$XDG_CONFIG_HOME/nvim"
"$dfp/text-editor/neovim/" "$HOME/.vim"
"$dfp/text-editor/neovim/init.vim" "$HOME/.vimrc"
"$dfp/common/colors/vim" "$XDG_CONFIG_HOME/nvim/colors/base16-donokai.vim"
# irc files
"$dfp/misc/irssi/" "$HOME/.irssi"
"$dfp/misc/weechat/" "$HOME/.weechat"
# neofetch config
"$dfp/misc/neofetch/config" "$HOME/.config/neofetch/config"
# git config
"$dfp/misc/git/config" "$HOME/.gitconfig"
)
source=""
for i in "${links[@]}"; do
if [ -n "$source" ]; then
if [ -L "$i" ]; then # if symlink exists, delete it
rm -rf "$i"
fi
if [ -f "$i" ]; then # if file exists, delete it
rm -rf "$i"
fi
if [ -d "$i" ]; then # if directory exists, delete it
rm -rf "$i"
fi
# check if the directory that will contain the link exists
DIR_TO_LINK=$(dirname "$i")
if [ -d "$DIR_TO_LINK" ]; then
:
else
mkdir -p "$DIR_TO_LINK"
fi
ln -s "$source" "$i"
echo "Linked $(basename $source) to $i."
source=""
else
source="$i"
fi
done
echo "Done."