Moving dotfiles to independent directory

This commit is contained in:
Christian Colglazier 2019-12-22 21:59:22 -05:00
parent 329aa603df
commit 46b4a3f945
2 changed files with 36 additions and 0 deletions

36
scripts/install.sh Normal file
View File

@ -0,0 +1,36 @@
#! /bin/bash
dotdir=~/dotfiles
# src dest sudo
files=($dotdir/.zshrc ~/ 'n' \
${dotdir}/alacritty/alacritty.yml ~/.config/alacritty/ 'n')
echo Setting up dotfiles...
#
for (( i=0; i<${#files[@]} ; i+=3 )) ; do
# Check if sudo is needed
pre=''
if [[ ${files[i+2]} == *'y'* ]]; then
pre='sudo'
fi
destPath=${files[i+1]}$(basename "${files[i]}")
# Check if file already exists
if [ -f $destPath ]; then
# Check if path is not a sybolic link
if ! [ -L $destPath ]; then
echo Backing up $destPath
$pre mv $destPath ${destPath}.bak
else
echo The file $destPath is already set up
continue
fi
else
echo $pre mkdir -p "$(dirname "$destPath")"
fi
echo Creating symbolic link from ${files[i]} to ${files[i+1]}
$pre ln -sf ${files[i]} ${files[i+1]}
done