-
Notifications
You must be signed in to change notification settings - Fork 2
/
_make_links
executable file
·63 lines (51 loc) · 1013 Bytes
/
_make_links
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
60
61
62
63
#! /bin/sh
DOT_DIR=${HOME}/.dot_files
die() {
echo 1>&2 "$*"
exit 1
}
verbose () {
[ "$VERBOSE" = "yes" ] && echo "$@"
}
debug() {
verbose "$@"
[ -z "$DEBUG" ] && "$@"
}
args=$(getopt dv "$*")
if [ $? != 0 ]; then
die "Usage: $0 [-d] [-v]"
fi
set -- $args
for arg in $args; do
case "$arg" in
-d)
DEBUG=yes
VERBOSE=yes
shift
;;
-v)
VERBOSE=yes
shift
;;
--)
shift
break
;;
esac
done
if [ "$DEBUG" = "yes" ]; then
echo "# Debug Mode: no commands will be run."
echo
fi
cd $DOT_DIR || die "Failed to cd into '$DOT_DIR'!"
for file in $(ls | egrep -v ^\(_\|\#\)); do
dest=${HOME}/.${file}
if [ -L "$dest" ]; then
verbose "# ${dest} is already a symlink... skipping."
continue
fi
if [ -e $dest ]; then
debug mv $dest ${dest}.bak
fi
debug ln -sv "${DOT_DIR}/$file" "$dest"
done