forked from holman/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
symlink-setup.sh
executable file
·43 lines (31 loc) · 1.11 KB
/
symlink-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
#!/bin/bash
# Install all symlinks from the dotfiles folder
source ./_utils.sh
# finds all .dotfiles
declare -a FILES_TO_SYMLINK=$(find dotfiles -maxdepth 1 -type f -name ".*")
FILES_TO_SYMLINK+=("bin") # add extra contents
main() {
local i=""
local sourceFile=""
local targetFile=""
for i in ${FILES_TO_SYMLINK[@]}; do
sourceFile="$(pwd)/$i"
targetFile="$HOME/$(echo $i | sed 's/dotfiles\///')"
if [ -e "$targetFile" ]; then
if [ "$(readlink "$targetFile")" != "$sourceFile" ]; then
ask_for_confirmation "'$targetFile' already exists, do you want to overwrite it?"
if answer_is_yes; then
rm -rf "$targetFile"
execute "ln -fs $sourceFile $targetFile" "$targetFile → $sourceFile"
else
print_error "$targetFile → $sourceFile"
fi
else
print_success "$targetFile → $sourceFile"
fi
else
execute "ln -fs $sourceFile $targetFile" "$targetFile → $sourceFile"
fi
done
}
main