-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.sh
executable file
·46 lines (37 loc) · 885 Bytes
/
setup.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
#!/bin/bash
current_dir=$(pwd)
dotfiles_dir="$HOME/.dotfiles"
dotfiles_dir_backups="$HOME/.dotfiles-backups"
function dotfiles() {
/usr/bin/git --git-dir="$HOME/.dotfiles/" --work-tree="$HOME" "$@"
}
function exit_if_err() {
if [[ $? -ne 0 ]]; then
exit 1
fi
}
function clone() {
if [[ -d $dotfiles_dir ]]; then
rm -rf $dotfiles_dir
fi
git clone -q --bare git@github.com:stefanolsenn/dotfiles.git $dotfiles_dir
echo "Cloned dotfiles"
}
function backup_existing_files() {
mkdir -p $dotfiles_dir_backups
cd $dotfiles_dir
tracked_files=$(git ls-tree -r master --name-only)
for file in $tracked_files;
do
mv -f $HOME/$file $dotfiles_dir_backups > /dev/null
done
cd $current_dir
echo "Backed up all existing files"
}
clone
backup_existing_files
dotfiles checkout
exit_if_err
dotfiles config status.showUntrackedFiles no
source "$HOME/.bashrc"
echo "OK!"