dotfiles/setup.sh

108 lines
2.5 KiB
Bash
Raw Permalink Normal View History

2017-11-03 07:09:33 +00:00
#!/bin/bash
2021-07-21 07:36:32 +00:00
set -u
mkdir -p ~/.config/homedir-backup 2>/dev/null
2022-05-01 18:10:08 +00:00
echo Doing self-update
if ! git pull ; then
echo "Git pull failed.. continuing in unknown state..."
fi
# Creates Directories & linkes files to this repo
2021-07-21 07:36:32 +00:00
function linkfiles {
for file in $@; do
name=$(basename $file)
dir=$(dirname $file)
if [ "$dir" == "dotfiles" ] ; then
targetdir=""
2022-02-15 07:55:29 +00:00
elif [ "$( dirname $dir | cut -f1 -d/)" == "configfile" ] ; then
targetdir="config/$(echo $dir | cut -f2- -d/)/"
2022-04-02 14:02:55 +00:00
mkdir -p "${HOME}/.${targetdir}"
2021-07-21 07:36:32 +00:00
else
targetdir="$dir/"
fi
2022-04-02 14:02:55 +00:00
if [ -f hosts/$(hostname -s)/${name} ] ; then
dotfile="$(pwd)/hosts/$(hostname -s)/${name}"
else
dotfile="$(pwd)/$dir/${name}"
fi
2022-02-15 07:55:29 +00:00
2022-04-02 14:02:55 +00:00
# Backup local dotfiles:
if [ ! -L ~/.${targetdir}${name} ] ; then
2022-05-01 18:10:08 +00:00
mkdir -p ~/.config/homedir-backup/${targetdir}
mv -v "${HOME}/.${targetdir}${name}" ~/.config/homedir-backup/${targetdir}
2022-04-02 14:02:55 +00:00
fi
2022-02-15 07:55:29 +00:00
2022-04-02 14:02:55 +00:00
# Fix broken links
if [ -L ~/.${targetdir}${name} ] ; then
rm -f "${HOME}/.${targetdir}${name}"
2021-07-21 07:36:32 +00:00
fi
2022-04-02 14:02:55 +00:00
ln -s "$dotfile" "${HOME}/.${targetdir}${name}"
2021-07-21 07:36:32 +00:00
done
}
2022-04-02 14:02:55 +00:00
linkfiles 'dotfiles/*'
2022-02-14 20:37:02 +00:00
# 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
2022-12-22 10:27:08 +00:00
nvim +'hi NormalFloat guibg=#1e222a' +PackerSync +':TSInstall diff lua markdown cpp gitcommit git_rebase yaml toml dockerfile python go php make jq bash vim json5'
# Link Config Directories
linkfiles 'config/*'
# Link Config Files
2022-02-15 07:55:29 +00:00
for file in $(find configfile -type f) ; do
linkfiles $file
done
2021-04-19 10:08:05 +00:00
# Install powerline if possible
if type pip3 &>/dev/null ; then
pip3 install --user -U -r requirements.txt
2021-04-19 10:08:05 +00:00
fi
2017-11-03 07:24:23 +00:00
2021-04-19 10:08:05 +00:00
# Install vundle plugin manager & plugins
2019-02-14 18:45:24 +00:00
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
2021-04-21 08:12:00 +00:00
# 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/
2021-04-21 08:12:00 +00:00
# Inject bashrc sourcing
2021-04-19 10:08:05 +00:00
grep -qE "^source.*$(pwd)/bashrc" ~/.bashrc || echo "source $(pwd)/bashrc" >> ~/.bashrc
echo
echo All Done. Happy Hacking.
2022-05-01 18:10:08 +00:00
exit 0