forked from aaronbieber/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkall
executable file
·112 lines (94 loc) · 2.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env zsh
# Color constants
yellow="\e[33;40m"
red="\e[31;40m"
green="\e[32;40m"
reset="\e[39;49m"
# 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`
BINPATH="$SCRIPTPATH/bin"
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
if [ -d "./$linkfile" ]
if [ -e "$linkfile" ]; then
echo -n "${yellow}Exists${reset}"
else
ln -s $LNOPTS "$dotfile" "./$linkfile" > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo -n "${green}OK${reset} "
else
echo -n "${red}Failed${reset}"
fi
fi
echo " $dotfile -> $linkfile... "
done
if [ ! -d "$HOME/bin" ]; then
echo "Creating ~/bin directory."
mkdir "$HOME/bin"
fi
# Return to original pwd.
popd > /dev/null
# Move into bin dir.
pushd "$HOME/bin" > /dev/null
echo ""
echo "Creating symlinks for executable scripts in $BINPATH."
echo ""
for script in `find $BINPATH -mindepth 1 -maxdepth 1 -not -name 'Makefile'`; do
linkfile="${script##*/}"
ln -s $LNOPTS "$script" "$linkfile" > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo -n "${green}OK${reset} "
else
if [ -f "$linkfile" ]; then
echo -n "${yellow}Exists${reset}"
else
echo -n "${red}Failed${reset}"
fi
fi
echo " $script -> $linkfile... "
done
# Return to original pwd.
popd > /dev/null