-
Notifications
You must be signed in to change notification settings - Fork 0
/
symlink.sh
executable file
·54 lines (46 loc) · 1.1 KB
/
symlink.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
#!/bin/bash
set -e
# add dotfiles to glob
shopt -s dotglob
# make glob return emptystring on nomatch
shopt -s nullglob
main() {
# for any dotfile except .. and .
echo "Installing dotfiles..."
for dotfile in .[^.]?*; do
case "$dotfile" in
.git) continue ;;
.gitmodules) continue ;;
*.sw*) continue ;;
esac
target="$HOME/$dotfile"
dotfile="$PWD/$dotfile"
install_symlink "$dotfile" "$target"
done
# for listed config
echo "Installing configs..."
for conf in config/*; do
target="$HOME/.config/$(basename "$conf")"
conf="$PWD/$conf"
install_symlink "$conf" "$target"
done
}
install_symlink() {
local src="$1"
local target="$2"
if [[ -L "$target" ]] && [[ "$(readlink "$target")" == "$src" ]]; then
echo "skipping: $src"
return
elif [[ -f "$target" ]] || [[ -d "$target" ]]; then
echo "move: $src -> ${source}.dist"
mv "$target" "$target.dist"
fi
if ! [[ -e "$target" ]]; then
echo "install: $src -> $target"
ln -sf "$src" "$target"
else
echo "PROBLEMO: Already exist and ain't symlink, regular file or dir: $target "
exit 1
fi
}
main