-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.sh
executable file
·50 lines (42 loc) · 966 Bytes
/
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
44
45
46
47
48
49
50
#!/usr/bin/env bash
#
# Set up links from $HOME to the individual files in this
# repository (unless the link names already exist)
#
def="\033[0m"
gray="\033[90m"
green="\033[92m"
yellow="\033[93m"
cyan="\033[96m"
set -e
cd "$(dirname "$0")/files"
pwd=$(pwd)
find . -type f | sort | while read rel_name
do
rel_name="${rel_name##./}"
link_name="$HOME/$rel_name"
target="$pwd/$rel_name"
if [ "$(dirname "$rel_name")" == '.' ]
then
fmt_name="$def$rel_name"
else
fmt_name="$gray$(dirname "$rel_name")/$def$(basename "$rel_name")"
fi
if [ -f "$link_name" ] || [ -L "$link_name" ]
then
if [ -L "$link_name" ]
then
link_target="$(readlink -m "$link_name")"
if [ "$link_target" == "$target" ]
then
echo -e " ${green}managed: $fmt_name$def"
continue
fi
fi
echo -e " ${yellow}manual: $fmt_name$def"
else
mkdir -p "$(dirname "$link_name")"
echo -e " ${cyan}link: $fmt_name$def"
ln -rs "$target" "$link_name"
fi
done