-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkall
executable file
·66 lines (57 loc) · 1.49 KB
/
linkall
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
64
65
66
#!/usr/bin/env zsh
# Who am I?
me=`basename $0`
# Get options.
LNOPTS=""
if [ $# -gt 0 ]; then
if [[ "$1" == "-f" ]]; then
LNOPTS="-f"
else
echo "Unrecognized option: $1"
cat << EOF
Usage: $me [OPTIONS]
Options:
-f Force 'ln' to create a new link, even if one already exists with the
same name.
EOF
exit 1
fi
fi
# The system name is used to link platform-specific files.
platform=`uname`
# This appears to be the "best" way to get the canonicalized path to where this
# script is located, which is, presumably, where all of my dotfiles are.
# Lifted from http://stackoverflow.com/a/4774063
pushd `dirname $0` > /dev/null
SCRIPTPATH=`pwd`
SCRIPTPATH="$SCRIPTPATH/configs"
popd > /dev/null
pushd ~ > /dev/null
echo "Creating symlinks for all configuration files in $SCRIPTPATH."
echo ""
for dotfile in `find $SCRIPTPATH -mindepth 1 -maxdepth 1`; do
if [[ "${dotfile##*/}" == "bashrc" ]]; then
linkfile=".bash_profile"
else
# If the dotfile starts with an underscore-braced string, only link it if
# that string matches our platform.
if [[ "${dotfile##*/}" =~ "_.*_" ]]; then
if [[ "${dotfile##*/}" =~ "_${platform}_" ]]; then
linkfile=".${dotfile##*/_${platform}_}"
else
continue
fi
else
# This is the common case. Link the base name.
linkfile=".${dotfile##*/}"
fi
fi
echo -n "Linking $dotfile -> $linkfile... "
ln -s $LNOPTS "$dotfile" "$linkfile" > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "OK"
else
echo "Failed"
fi
done
popd > /dev/null