-
Notifications
You must be signed in to change notification settings - Fork 1
/
link_dot_files.sh
executable file
·41 lines (39 loc) · 1.06 KB
/
link_dot_files.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
#!/bin/sh -e
safeLn() {
srcFile=$1
target=$2
linkTarget=$2
[ -e "$srcFile" ]
if [ -d "$target" ]; then
target="$target/$(basename "$srcFile")"
fi
if [ ! -e "$target" ] || diff -q "$srcFile" "$target"; then
ln -sf "$srcFile" "$linkTarget"
else
diff -u "$srcFile" "$target" || true
echo "Override and link $target to $srcFile ? Y/n"
read -r ans
if [ "$ans" = Y ] || [ "$ans" = y ]; then
[ -d "$target" ] && rm -r "$target"
ln -sf "$srcFile" "$linkTarget"
fi
fi
}
SYSTEM_CONFIG_DIR=${SYSTEM_CONFIG_DIR:-~/SystemConfig}
if [ -z "$1" ]; then
cd "$SYSTEM_CONFIG_DIR/Config"
else
cd "$SYSTEM_CONFIG_DIR/$1"*
fi
for dotFile in .*; do
if [ "$dotFile" = "." ] || [ "$dotFile" = ".." ]; then
continue
elif [ -d "$dotFile" ]; then
mkdir -p "$HOME/$dotFile"
for config in "$dotFile"/*; do
[ -e "$config" ] && safeLn "$PWD/$config" "$HOME/$dotFile/"
done
else
safeLn "$PWD/$dotFile" "$HOME/$dotFile"
fi
done