-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·45 lines (38 loc) · 1.5 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# A script to clone this repository and symlink the dotfiles to the home directory.
# -----------------------------------------------------------------------------
if ! command -v git &> /dev/null; then
if ! command -v brew &> /dev/null; then
echo "Installing Homebrew."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
echo "Installing git."
brew install git
fi
dotfiles_dir=$HOME/.dotfiles
if [ -d $dotfiles_dir ]; then
while read -p "Dotfiles directory '$dotfiles_dir' already exists, would you like to overwrite it? (yes/no) " yn; do
case $yn in
yes) echo "Deleting $dotfiles_dir"; rm -rf $dotfiles_dir; break;;
no) exit;;
* ) echo "Please answer yes or no.";;
esac
done
fi
echo "Creating dotfiles directory '$dotfiles_dir'."
mkdir -p $dotfiles_dir
echo "Cloning dotfiles repository into '$dotfiles_dir'."
git clone --quiet https://github.com/maximus1108/dotfiles.git $dotfiles_dir
cd $dotfiles_dir
dotfiles=$(ls -a dotfiles | xargs -I{} bash -c "if ! [ -d {} ]; then echo {}; fi")
backup_folder=$HOME/.dotfiles-backup
mkdir -p $backup_folder
for dotfile in $dotfiles; do
if [ -f $HOME/$dotfile ]; then
echo "Backing up pre-existing $dotfile in $backup_folder.";
mv $HOME/$dotfile $backup_folder/$dotfile
fi
echo "Creating symlink for $dotfile."
ln -s -f $dotfiles_dir/dotfiles/$dotfile $HOME/$dotfile
done