-
Notifications
You must be signed in to change notification settings - Fork 0
/
place_dotfiles.sh
executable file
·205 lines (183 loc) · 7.3 KB
/
place_dotfiles.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/sh
MYDIR="$(dirname "$(realpath "$0")")"
VIMGITFOLDER=$MYDIR'/vim_git/'
ZSHGITFOLDER=$MYDIR'/zsh_git/'
MYOUTPUT="/tmp/dotfile_replace.txt"
if test -f "$MYOUTPUT" ; then
true > "$MYOUTPUT"
fi
if test "$1" = '-z' ; then
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
if test -z $ZSH_CUSTOM ; then
ZSHGITDIR_PLUGINS="$HOME"'/.oh-my-zsh/custom/plugins'
ZSHGITDIR_THEMES="$HOME"'/.oh-my-zsh/custom/themes'
else
ZSHGITDIR_PLUGINS="$HOME"'/'"$ZSH_CUSTOM"'/plugins'
ZSHGITDIR_THEMES="$HOME"'/'"$ZSH_CUSTOM"'/themes'
fi
for i in $(perl -n -e '/\((.*)\)/ && print $1." "' zshplugin_externals.md) ; do
PLUGIN="$(printf '%s' "$i" | awk 'BEGIN {FS="/"};{print $NF}')"
printf 'getting: %s\n' "$PLUGIN"
if ! git clone "$i"'.git' "$ZSHGITFOLDER$PLUGIN" ; then
printf 'Folder already present, running git pull\n'
git -C "$ZSHGITFOLDER$PLUGIN" pull
fi
done
for i in $(perl -n -e '/\((.*)\)/ && print $1." "' zshplugin_externals.md) ; do
PLUGIN="$(printf '%s' "$i" | awk 'BEGIN {FS="/"};{print $NF}')"
printf 'linking: %s\n' "$PLUGIN"
if test -L "$ZSHGITDIR_PLUGINS"'/'"$PLUGIN" ; then
printf '%s is already symlinked to %s, removing.\n' "$PLUGIN" "$(readlink "$ZSHGITDIR"'/'"$PLUGIN")"
rm "$ZSHGITDIR_PLUGINS"'/'"$PLUGIN"
elif test -f "$ZSHGITDIR_PLUGINS"'/'"$PLUGIN" ; then
printf '%s is a real file, backing up to %s.bak' "$ZSHGITDIR_PLUGINS"'/'"$PLUGIN" \
"$PLUGIN"
if ! cp -pn "$ZSHGITDIR_PLUGINS"'/'"$PLUGIN" "$ZSHGITDIR_PLUGINS"'/'"$PLUGIN"'.bak' ; then
printf '%s.bak already exists, exiting to allow manual intervention.' \
"$PLUGIN"
exit 1
else
rm "$ZSHGITDIR_PLUGINS"'/'"$PLUGIN"
fi
fi
ln -vs "$MYDIR"'/zsh_git/'"$PLUGIN" "$ZSHGITDIR_PLUGINS"'/'"$PLUGIN" >> "$MYOUTPUT"
done
for i in $(perl -n -e '/\((.*)\)/ && print $1." "' zshtheme_externals.md) ; do
PLUGIN="$(printf '%s' "$i" | awk 'BEGIN {FS="/"};{print $NF}')"
printf 'getting: %s\n' "$PLUGIN"
if ! git clone "$i"'.git' "$ZSHGITFOLDER$PLUGIN" ; then
printf 'Folder already present, running git pull\n'
git -C "$ZSHGITFOLDER$PLUGIN" pull
fi
done
for i in $(perl -n -e '/\((.*)\)/ && print $1." "' zshtheme_externals.md) ; do
PLUGIN="$(printf '%s' "$i" | awk 'BEGIN {FS="/"};{print $NF}')"
printf 'linking: %s\n' "$PLUGIN"
if test -L "$ZSHGITDIR_THEMES"'/'"$PLUGIN" ; then
printf '%s is already symlinked to %s, removing.\n' "$PLUGIN" "$(readlink "$ZSHGITDIR"'/'"$PLUGIN")"
rm "$ZSHGITDIR_THEMES"'/'"$PLUGIN"
elif test -f "$ZSHGITDIR_THEMES"'/'"$PLUGIN" ; then
printf '%s is a real file, backing up to %s.bak' "$ZSHGITDIR_THEMES"'/'"$PLUGIN" \
"$PLUGIN"
if ! cp -pn "$ZSHGITDIR_THEMES"'/'"$PLUGIN" "$ZSHGITDIR_THEMES"'/'"$PLUGIN"'.bak' ; then
printf '%s.bak already exists, exiting to allow manual intervention.' \
"$PLUGIN"
exit 1
else
rm "$ZSHGITDIR_THEMES"'/'"$PLUGIN"
fi
fi
ln -vs "$MYDIR"'/zsh_git/'"$PLUGIN" "$ZSHGITDIR_THEMES"'/'"$PLUGIN" >> "$MYOUTPUT"
done
fi
RCFILES='bashrc.sh vimrc.vim zshrc.zsh'
EXT_FILES=''
for i in ext_* ; do
if test "$i" = 'ext_*' && ! test -e 'ext_*' ; then
continue # nullglob
fi
EXT_FILES="$EXT_FILES $i"
done
for i in ext/ext_* ; do
if test "$i" = 'ext/ext_*' && ! test -e 'ext/ext_*' ; then
continue # nullglob
fi
EXT_FILES="$EXT_FILES $i"
done
for FILE in $RCFILES $EXT_FILES ; do # Space splitting intentional
case $FILE in
'ext/'*) DOTFILE='.'"$(printf '%s' "$FILE" | cut -c5- )" ;;
'ext_'*) DOTFILE='.'"$(printf '%s' "$FILE" )";;
*) DOTFILE='.'"$(printf '%s' "$FILE" | rev | cut -f 2- -d '.' | rev)" ;;
esac
if test -L "$HOME"'/'"$DOTFILE" ; then
printf '%s is already symlinked to %s, removing.\n' "$DOTFILE" "$(readlink "$HOME"'/'"$DOTFILE")"
rm "$HOME"'/'"$DOTFILE"
elif test -f "$HOME"'/'"$DOTFILE" ; then
printf '%s is a real file, backing up to %s.bak' "$DOTFILE" "$DOTFILE"
if ! cp -pn "$HOME"'/'"$DOTFILE" "$HOME"'/'"$DOTFILE"'.bak' ; then
printf '%s.bak already exists, exiting to allow manual intervention.' \
"$DOTFILE"
exit 1
else # Copy good, remove file
rm "$HOME"'/'"$DOTFILE"
fi
fi
ln -vs "$MYDIR"'/'"$FILE" "$HOME"'/'"$DOTFILE" >> "$MYOUTPUT"
done
if ! test -d "$HOME/.vim/plugin" ; then
printf 'Creating %s/.vim/plugin.' "$HOME"
mkdir -p "$HOME/.vim/plugin/"
fi
mkdir ~/.vim/backup ~/.vim/swap ~/.vim/undo
VIMDIR="$HOME/.vim/plugin"
for FILE in "$MYDIR"'/vimplugins/'*'.vim' ; do
FILENAME="$(basename "$FILE")"
if test -L "$VIMDIR"'/'"$FILENAME" ; then
printf '%s is already symlinked to %s, removing.\n' "$FILENAME" "$(readlink "$VIMDIR"'/'"$FILENAME")"
rm "$VIMDIR"'/'"$FILENAME"
elif test -f "$VIMDIR"'/'"$FILENAME" ; then
printf '%s is a real file, backing up to %s.bak' "$VIMDIR"'/'"$FILENAME" \
"$FILENAME"
if ! cp -pn "$VIMDIR"'/'"$FILENAME" "$VIMDIR"'/'"$FILENAME"'.bak' ; then
printf '%s.bak already exists, exiting to allow manual intervention.' \
"$FILENAME"
exit 1
fi
fi
ln -vs "$FILE" "$VIMDIR"'/'"$FILENAME" >> "$MYOUTPUT"
done
if ! test -d "$VIMDIR" ; then
printf 'Making folder for external git files from vim.'
mkdir "$VIMDIR"
fi
for i in $(perl -n -e '/\((.*)\)/ && print $1." "' vimplugin_externals.md) ; do
PLUGIN="$(printf '%s' "$i" | awk 'BEGIN {FS="/"};{print $NF}')"
printf 'getting: %s\n' "$PLUGIN"
if ! git clone "$i"'.git' "$VIMGITFOLDER$PLUGIN" ; then
printf 'Folder already present, running git pull\n'
git -C "$VIMGITFOLDER$PLUGIN" pull
fi
done
if ! test -d "$HOME/.vim/pack/default/start" ; then
printf 'Creating %s/.vim/pack/default/start' "$HOME"
mkdir -p "$HOME/.vim/pack/default/start/"
fi
VIMGITDIR="$HOME/.vim/pack/default/start/"
for i in $(perl -n -e '/\((.*)\)/ && print $1." "' vimplugin_externals.md) ; do
PLUGIN="$(printf '%s' "$i" | awk 'BEGIN {FS="/"};{print $NF}')"
printf 'linking: %s\n' "$PLUGIN"
if test -L "$VIMGITDIR"'/'"$PLUGIN" ; then
printf '%s is already symlinked to %s, removing.\n' "$PLUGIN" "$(readlink "$VIMGITDIR"'/'"$PLUGIN")"
rm "$VIMGITDIR"'/'"$PLUGIN"
elif test -f "$VIMGITDIR"'/'"$PLUGIN" ; then
printf '%s is a real file, backing up to %s.bak' "$VIMGITDIR"'/'"$PLUGIN" \
"$PLUGIN"
if ! cp -pn "$VIMGITDIR"'/'"$PLUGIN" "$VIMGITDIR"'/'"$PLUGIN"'.bak' ; then
printf '%s.bak already exists, exiting to allow manual intervention.' \
"$PLUGIN"
exit 1
fi
fi
ln -vs "$MYDIR"'/vim_git/'"$PLUGIN" "$VIMGITDIR""$PLUGIN" >> "$MYOUTPUT"
done
if test "$OSTYPE" = "darwin" ; then
NIXFLDR="$HOME"'/.nixpkgs/'
if ! test -d "$NIXFLDR"; then
mkdir -p "$NIXFLDR"
fi
DARWINCONF="$NIXFLDR"'darwin-configuration.nix'
if test -L ; then
printf '%s is already symlinked to %s, removing.\n' "$DARWINCONF" "$(readlink "$DARWINCONF")"
rm "$DARWINCONF"
elif test -f "$DARWINCONF" ; then
printf '%s is a real file, backing up to %s.bak' "$DARWINCONF" "$DARWINCONF"
if ! cp -pn "$DARWINCONF" "$DARWINCONF"'.bak' ; then
printf '%s.bak already exists, exiting to allow manual intervention.' \
"$DARWINCONF"
exit 1
fi
fi
ln -vs "$MYDIR"'/darwin-configuration.nix' "$DARWINCONF" >> "$MYOUTPUT"
fi
cat "$MYOUTPUT"