-
Notifications
You must be signed in to change notification settings - Fork 3
/
link-dotfiles.sh
executable file
·59 lines (51 loc) · 1.19 KB
/
link-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
#!/bin/bash
set -euf -o pipefail
force_delete=0
DOTS="$PWD"
uname="$(uname)"
while [ $# -gt 0 ]
do
case "$1" in
(-f) force_delete=1; shift;;
(-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;;
(*) break;;
esac
shift
done
symlink(){
file="$1"
src="$DOTS/$file"
trg="${2-"$HOME/$file"}"
if [ ! -e "$src" ]; then
echo "[error] $src does not exist!"
return
fi
if [ -e "$trg" ]; then
if [ $force_delete == 1 ]; then
rm -rf "$trg"
ln -sv "$src" "$trg"
else
echo "[error] unable to symlink $src; $trg exists."
fi
else
mkdir -p "$(dirname "$trg")"
ln -fsv "$src" "$trg"
fi
}
dot_files=$(
find . -maxdepth 1 -name '.*' \
! -name '.' \
! -name '.AppleDouble' \
! -name '.DS_Store' \
! -name '.git' \
! -name '.github' \
! -name '.gitignore' \
! -name '.gitmodules' \
! -name '.macos'
)
# Anything that starts with a dot should be linked as is.
for dotfile in $dot_files; do
symlink "$(basename "$dotfile")"
done
# special cases - these don't start with a dot
symlink "bin.$uname" $HOME/bin