-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_links.sh
executable file
·186 lines (163 loc) · 5.45 KB
/
create_links.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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/env bash
########################################
# This is the list of conf files that we
# want to automagically link after
# checking out to the remote machine
########################################
# 'remove' means to remove the files so they can be linked
# 'cleanup' means to remove all the files created by this script
remove="$1"
dotfiles_loc=$(cd `dirname $0` && pwd)
excluded=(
.svn
.git
.DS_Store
.
..
)
# make sure the dotfiles are only rwx by the owner
chmod 700 $dotfiles_loc
notExcluded() {
# check that the value exists
if [ -z "$1" ]; then
return
fi
for i in ${excluded[@]}
do
if [ $i == $1 ]; then
# the item exists
return 1
fi
done
# it did not exist
return 0
}
linkDotfile() {
dotfile="$1"
to_create="$2"
actual_dotfile="$3"
# clean up if requested
if [ "$remove" = "remove" ] || [ "$remove" = "cleanup" ]; then
if [ -e "$to_create" ]; then
rm "$to_create"
echo "Deleted $to_create"
fi
else
# symlink the conf file
if [ ! -e "$to_create" ]; then
echo "linking $actual_dotfile to $to_create"
ln -s $actual_dotfile $to_create
fi
# warn the user that an existing file is in the way
if [ ! -h "$to_create" -a -e "$to_create" ]; then
echo "Remove $to_create so that it can be linked"
fi
fi
}
# Links all the dotfiles from the .dotfiles directory
# -----------------------------------------------------------------
for actual_dotfile in $(ls -d ${dotfiles_loc}/.*)
do
dotfile=$(echo $actual_dotfile | awk -F"$dotfiles_loc/" '{print $2}')
# ignore certain directories
if notExcluded $dotfile; then
to_create="$HOME/$dotfile"
linkDotfile $dotfile $to_create $actual_dotfile
fi
done
# TODO: Modify creation script to handle nested directories that
# aren't under version control.
###################################################################
# NOTE: None of these files are under version control...
# -----------------------------------------------------------------
if [ ! "$remove" = "remove" ]; then
# warn the user what is about to happen
if [ "$remove" = "cleanup" ]; then
echo '
******************************************
These files are not under version control
Deleting them will remove them immediately
******************************************
'
fi
# touch extra files needed by the confs
# -------------------------------------------------------------
touch_me=(
.zsh_history
.bash_history
.zshextras
.zshenv_extras
.bash_extras
)
for to_touch in "${touch_me[@]}"
do
TOUCH_FILE="$HOME/$to_touch"
# if we are cleaning up offer to delete these files
if [ "$remove" = "cleanup" ]; then
if [ -e "$TOUCH_FILE" ]; then
echo -n "Are you sure you want to delete $TOUCH_FILE? [n]: "
read REMOVE_FILE
if [ "$REMOVE_FILE" = "y" ]; then
rm "$TOUCH_FILE"
echo "Deleted $TOUCH_FILE"
fi
fi
# touch the files if they don't exist
elif [ ! -e "$TOUCH_FILE" ]; then
echo "touching $TOUCH_FILE"
touch "$TOUCH_FILE"
chmod 600 "$TOUCH_FILE"
fi
done
DIRS_TO_MAKE=(
"$HOME"/bin
"$HOME"/.backup
"$HOME"/.backup/vim/swap
"$HOME"/.config/alacritty
"$HOME"/.config/Code/User
"$HOME"/.config/nvim
)
# create the $DIRS_TO_MAKE
# -------------------------------------------------------------
processDotDir() {
local dot_directory
dot_directory=$1
# if we are cleaning up, let's remove the dir
if [ "$remove" = "cleanup" ]; then
if [ -d "$dot_directory" ]; then
echo -n "Are you sure you want to delete $dot_directory? [n]: "
read REMOVE_DIR
if [ "$REMOVE_DIR" = "y" ]; then
rm -rf "$dot_directory"
echo "Deleted $dot_directory"
fi
fi
# if the directory doesn't exist, let's create it
elif [[ ! -d "$dot_directory" ]] && [[ ! -a "$dot_directory" ]]; then
mkdir -p "$dot_directory" && echo "created a $dot_directory directory"
chmod 700 "$dot_directory"
elif [[ ! -d "$dot_directory" ]] && [[ -a "$dot_directory" ]]; then
echo "something in the way of $dot_directory being created"
fi
}
for dir in "${DIRS_TO_MAKE[@]}"
do
processDotDir $dir
done
fi
actual_dotfile="$dotfiles_loc/.config/alacritty/alacritty.yml"
dotfile="alacritty.yml"
to_create="$HOME/.config/alacritty/$dotfile"
linkDotfile $dotfile $to_create $actual_dotfile
actual_dotfile="$dotfiles_loc/.config/Code/User/settings.json"
dotfile="settings.json"
to_create="$HOME/.config/Code/User/$dotfile"
linkDotfile $dotfile $to_create $actual_dotfile
actual_dotfile="$dotfiles_loc/.config/nvim/init.vim"
dotfile="init.vim"
to_create="$HOME/.config/nvim/$dotfile"
linkDotfile $dotfile $to_create $actual_dotfile
# Set up our projects directory in case it's not already there.
if [[ -d $HOME/projects ]]; then
mkdir $HOME/projects
fi