-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinker.sh
executable file
·29 lines (26 loc) · 928 Bytes
/
linker.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
#!/bin/bash
# Links everything in home/ to ~/, does sanity checks.
# By Simon Eskildsen (github.com/Sirupsen)
function symlink {
ln -nsf $1 $2
}
for file in home/.[^.]*; do
path="$(pwd)/$file"
base=$(basename $file)
target="$HOME/$(basename $file)"
if [[ -h $target && ($(readlink $target) == $path)]]; then
echo -e "\x1B[37m~/$base is symlinked to your dotfiles.\x1B[39m"
elif [[ -f $target && $(md5sum $path) == $(md5sum $target) ]]; then
echo -e "\x1B[32m~/$base exists and was identical to your dotfile. Overriding with symlink.\x1B[39m"
symlink $path $target
elif [[ -a $target ]]; then
echo -en "\x1B[33m~/$base exists and differs from your dotfile. Override? [yn]\x1B[39m"
read -n 1; echo ""
if [[ $REPLY =~ [yY]* ]]; then
symlink $path $target
fi
else
echo -e "\x1B[32m~/$base does not exist. Symlinking to dotfile.\x1B[39m"
symlink $path $target
fi
done