dotfiles/setup.sh
2022-05-01 20:10:08 +02:00

107 lines
2.4 KiB
Bash
Executable file

#!/bin/bash
set -u
mkdir -p ~/.config/homedir-backup 2>/dev/null
echo Doing self-update
if ! git pull ; then
echo "Git pull failed.. continuing in unknown state..."
fi
# Creates Directories & linkes files to this repo
function linkfiles {
for file in $@; do
name=$(basename $file)
dir=$(dirname $file)
if [ "$dir" == "dotfiles" ] ; then
targetdir=""
elif [ "$( dirname $dir | cut -f1 -d/)" == "configfile" ] ; then
targetdir="config/$(echo $dir | cut -f2- -d/)/"
mkdir -p "${HOME}/.${targetdir}"
else
targetdir="$dir/"
fi
if [ -f hosts/$(hostname -s)/${name} ] ; then
dotfile="$(pwd)/hosts/$(hostname -s)/${name}"
else
dotfile="$(pwd)/$dir/${name}"
fi
# Backup local dotfiles:
if [ ! -L ~/.${targetdir}${name} ] ; then
mkdir -p ~/.config/homedir-backup/${targetdir}
mv -v "${HOME}/.${targetdir}${name}" ~/.config/homedir-backup/${targetdir}
fi
# Fix broken links
if [ -L ~/.${targetdir}${name} ] ; then
rm -f "${HOME}/.${targetdir}${name}"
fi
ln -s "$dotfile" "${HOME}/.${targetdir}${name}"
done
}
linkfiles 'dotfiles/*'
# Clones repo to dir, or pulls repo if dir already exists
# Params:
# git-repo-url target-dir [clone options]
function git-sync {
repo=$1
dir=$2
shift; shift
if [ ! -d "$dir" ] ; then
mkdir -p "$dir"
git clone --depth=1 $@ "$repo" "$dir"
return 0
else
git -C "$dir" pull
return 1
fi
}
linkfiles 'dotfiles/*'
# NeoVIM & NvChad
git-sync https://github.com/NvChad/NvChad ~/.config/nvim
nvim +'hi NormalFloat guibg=#1e222a' +PackerSync
# Link Config Directories
linkfiles 'config/*'
# Link Config Files
for file in $(find configfile -type f) ; do
linkfiles $file
done
# Install powerline if possible
if type pip3 &>/dev/null ; then
pip3 install --user -U -r requirements.txt
fi
# Install vundle plugin manager & plugins
mkdir -p ~/.vim/bundle 2>/dev/null
# Legacy Vim
if git-sync https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim; then
vim -c ":PluginInstall" -c ":q" -c ":q"
else
vim -c ":PluginUpdate" -c ":q" -c ":q"
fi
# Tmux Plugin Manager
mkdir -p ~/.tmux/plugins 2>/dev/null
git-sync https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
# Copy fonts
mkdir -p ~/.fonts/
cp fonts/* ~/.fonts/
# Inject bashrc sourcing
grep -qE "^source.*$(pwd)/bashrc" ~/.bashrc || echo "source $(pwd)/bashrc" >> ~/.bashrc
echo
echo All Done. Happy Hacking.
exit 0