-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstall-dotfiles.sh
executable file
·68 lines (51 loc) · 1.47 KB
/
install-dotfiles.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
echo "INFO: Installing dotfiles."
# Check that dotfiles repo exists.
[[ -d $HOME/dotfiles ]] || {
echo "Please ensure the dotfiles repo exists before running this command."
exit 1
}
echo "INFO: Updating submodules."
cd $HOME/dotfiles
git submodule update --init
# Backup old files.
[[ -d $HOME/.dotfiles-backup ]] || {
mkdir $HOME/.dotfiles-backup
}
# Run this from the user's home directory.
cd $HOME
# Files to exclude.
excluded=(".gitignore" ".hgignore" ".git" ".dotfiles-backup" ".." "." "install-dotfiles.sh" "agnoster-smerrill.zsh-theme")
for i in dotfiles/.*; do
# @TODO: DRY
for j in ${excluded[@]}; do
[[ $i == "dotfiles/$j" ]] && continue 2
done
existing_file=${i/dotfiles\//~/}
echo $existing_file
# Back up the file if it exists.
[[ -e $existing_file ]] && {
echo "INFO: Backing up $existing_file."
cp -frv $existing_file .dotfiles-backup/
}
# Make the symlink
ln -sfv $i $existing_file
done
for i in dotfiles/*; do
# @TODO: DRY
for j in ${excluded[@]}; do
[[ $i == "dotfiles/$j" ]] && continue 2
done
existing_file=${i/dotfiles\//~/}
echo $existing_file
# Back up the file if it exists.
[[ -e $existing_file ]] && {
echo "INFO: Backing up $existing_file."
cp -frv $existing_file .dotfiles-backup/
}
# Make the symlink
ln -sfv $i $existing_file
done
echo "INFO: Installing oh-my-zsh theme."
ln -sfv $HOME/dotfiles/agnoster-smerrill.zsh-theme $HOME/.oh-my-zsh/themes
echo "INFO: Dotfiles installed."