-
Notifications
You must be signed in to change notification settings - Fork 2
/
install
executable file
·259 lines (234 loc) · 9.22 KB
/
install
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/bin/bash
# detect platform (darwin, linux)
ec_platform='unknown'
if [[ ${OSTYPE} == darwin* ]]; then
ec_platform='darwin'
elif [[ ${OSTYPE} == linux* ]]; then
ec_platform='linux'
else
echo "Error: unknown OS type \"${OSTYPE}\""
exit 1
fi
# load existing settings (usually ~/.env-config/settings)
eval ec_dir="${ENV_CONFIG_DIR}"
if [[ -n ${ec_dir} && -f "${ec_dir}/settings" ]]; then
source "${ec_dir}/settings"
fi
ENV_CONFIG_PLATFORM="${ec_platform}"
# use defaults if something was not set
: ${ENV_CONFIG_DIR:='~/.env-config'}
: ${ENV_CONFIG_COLORS:='yes'}
: ${ENV_CONFIG_BASH_PROMPT_GIT_BRANCH:='yes'}
: ${ENV_CONFIG_BASH_PROMPT_MARKS:='yes'}
# for specifed feature name set corresponding setting to specified value
function ec_set_feature_var {
local feature="${1}"
local value="${2}"
case "${feature}" in
colors) ENV_CONFIG_COLORS="${value}";;
bash-prompt-git-branch) ENV_CONFIG_BASH_PROMPT_GIT_BRANCH="${value}";;
bash-prompt-marks) ENV_CONFIG_BASH_PROMPT_MARKS="${value}";;
*) echo "Error: unknown feature \"${feature}\""; exit 1;;
esac
}
# process command line arguments
ec_src=$(dirname "${BASH_SOURCE[0]}")
ec_verbose='no'
ec_dryrun='no'
while getopts ":hvty:n:d:" OPT; do
case "${OPT}" in
h)
echo "Options are:"
echo " -h - show this help"
echo " -v - verbose output"
echo " -t - dry run"
echo " -y <feature> - enable feature"
echo " -n <feature> - disable feature"
echo " -d <dir> - install to dir (default is \"${ENV_CONFIG_DIR}\")"
echo ""
echo "Features:"
echo " colors - more colors"
echo " readline - readline config file"
echo " bash-prompt-git-branch - git branch name in bash command prompt"
echo " bash-prompt-marks - text notes in bash command prompt"
exit 1
;;
v)
ec_verbose='yes'
;;
t)
ec_dryrun='yes'
;;
y)
ec_set_feature_var "${OPTARG}" 'yes'
;;
n)
ec_set_feature_var "${OPTARG}" 'no'
;;
d)
ENV_CONFIG_DIR="${OPTARG}"
;;
\?)
echo "Error: invalid option -${OPTARG}"
exit 1
;;
:)
echo "Error: option -${OPTARG} requires an argument"
exit 1
;;
esac
done
# check install dir path (must not have spaces or complex substitutions)
eval ec_dir="${ENV_CONFIG_DIR}"
ec_dir_stripped="${ENV_CONFIG_DIR#\~}"
ec_dir_check=$(printf '%q' "${ec_dir_stripped}")
if [[ ${ec_dir_check} != ${ec_dir_stripped} ]]; then
echo "Error: install dir \"${ENV_CONFIG_DIR}\" must not contain spaces, variables or other expandable tokens (except ~)"
echo "Error: \"${ec_dir_check}\" != \"${ec_dir_stripped}\""
exit 1
fi
ec_dir_check="${ENV_CONFIG_DIR/#~/${HOME}}"
if [[ ${ec_dir_check} != ${ec_dir} ]]; then
echo "Error: install dir \"${ENV_CONFIG_DIR}\" requires complex substitution that is not supported"
echo "Error: \"${ec_dir_check}\" != \"${ec_dir}\""
exit 1
fi
if [[ ${ec_dir} != /* ]]; then
echo "Error: install dir \"${ENV_CONFIG_DIR}\" doesn't evaluate to absolute path (\"${ec_dir}\")"
exit 1
fi
# print settings
if [[ ${ec_verbose} == 'yes' ]]; then
echo "Source dir: \"${ec_src}\""
echo "Install dir: \"${ENV_CONFIG_DIR}\" (\"${ec_dir}\")"
echo "Platform: \"${ENV_CONFIG_PLATFORM}\""
echo "Colors: \"${ENV_CONFIG_COLORS}\""
echo "Bash prompt with git branch: \"${ENV_CONFIG_BASH_PROMPT_GIT_BRANCH}\""
echo "Bash prompt with text marks: \"${ENV_CONFIG_BASH_PROMPT_MARKS}\""
echo "Dryrun: \"${ec_dryrun}\""
fi
# append one file to another performing some substitutions in the first one
function ec_append_init_script {
local init_script="${1}"
local dst_file="${2}"
if ! grep -Fq 'env-config+magic' "${dst_file}" &> /dev/null; then
# 'env-config+magic' was not found in ${dst_file}
# It is OK to append init script.
if [[ -s ${dst_file} ]]; then
# If ${dst_file} not empty, append extra empty line for nice style
echo >> "${dst_file}" || exit 1
fi
sed \
-e "s;<\[ENV_CONFIG_DIR\]>;${ENV_CONFIG_DIR};g" \
"${init_script}" >> "${dst_file}" || exit 1
fi
}
# extract annotated documentation
function ec_get_docs {
local afile="${1}"
local doc='^.*@env-config-doc'
sed -n "/${doc}[ \t]*/s/${doc}//p" "${afile}" || exit 1
}
# install / update
if [[ ${ec_dryrun} == 'no' ]]; then
# backup old env-config
ec_dir_backup="${ec_dir}.backup"
if [[ -d ${ec_dir_backup} ]]; then
rm -rf "${ec_dir_backup}"
mv -f "${ec_dir}" "${ec_dir_backup}" || exit 1
fi
# prepare folder
mkdir -p "${ec_dir}" || exit 1
# settings file
ec_settings_file="${ec_dir}/settings"
rm -f "${ec_settings_file}"
echo "ENV_CONFIG_PLATFORM='${ENV_CONFIG_PLATFORM}'" >> ${ec_settings_file} || exit 1
echo "ENV_CONFIG_COLORS='${ENV_CONFIG_COLORS}'" >> ${ec_settings_file} || exit 1
echo "ENV_CONFIG_BASH_PROMPT_GIT_BRANCH='${ENV_CONFIG_BASH_PROMPT_GIT_BRANCH}'" >> ${ec_settings_file} || exit 1
echo "ENV_CONFIG_BASH_PROMPT_MARKS='${ENV_CONFIG_BASH_PROMPT_MARKS}'" >> ${ec_settings_file} || exit 1
# readline
mkdir -p "${ec_dir}/readline" || exit 1
ec_get_docs "${ec_src}/readline/inputrc"
cp "${ec_src}/readline/inputrc" "${ec_dir}/readline/inputrc" || exit 1
ec_append_init_script "${ec_src}/readline/inputrc-init" ~/.inputrc
# bash - copy
mkdir -p "${ec_dir}/bash" || exit 1
ec_get_docs "${ec_src}/bash/bashrc"
cp "${ec_src}/bash/bashrc" "${ec_dir}/bash/bashrc" || exit 1
# https://raw.github.com/git/git/master/contrib/completion/git-completion.bash
cp "${ec_src}/bash/git-completion.bash" "${ec_dir}/bash/git-completion.bash" || exit 1
# https://svn.apache.org/repos/asf/subversion/trunk/tools/client-side/bash_completion
cp "${ec_src}/bash/svn-completion.bash" "${ec_dir}/bash/svn-completion.bash" || exit 1
# bash - source
case ${ENV_CONFIG_PLATFORM} in
'darwin') ec_bashrc_file=~/.bash_profile;;
'linux') ec_bashrc_file=~/.bashrc;;
*) echo "Error: unknown platform \"${ENV_CONFIG_PLATFORM}\""; exit 1;;
esac
ec_append_init_script "${ec_src}/bash/bashrc-init" "${ec_bashrc_file}"
# fish - copy
mkdir -p "${ec_dir}/fish" || exit 1
ec_get_docs "${ec_src}/fish/config.fish"
cp "${ec_src}/fish/config.fish" "${ec_dir}/fish/config.fish" || exit 1
# fish - source
mkdir -p ~/.config/fish || exit 1
ec_append_init_script "${ec_src}/fish/config.fish-init" ~/.config/fish/config.fish
# vim - copy
mkdir -p "${ec_dir}/vim" || exit 1
mkdir -p "${ec_dir}/vim/plugin" || exit 1
mkdir -p "${ec_dir}/vim/syntax" || exit 1
mkdir -p "${ec_dir}/vim/indent" || exit 1
# https://raw.github.com/ciaranm/securemodelines/master/plugin/securemodelines.vim
cp "${ec_src}/vim/plugin/securemodelines.vim" "${ec_dir}/vim/plugin/securemodelines.vim" || exit 1
# https://raw.github.com/xianxu/vim-settings/master/.vim/plugin/file_line.vim
cp "${ec_src}/vim/plugin/file_line.vim" "${ec_dir}/vim/plugin/file_line.vim" || exit 1
# https://raw.github.com/vim-scripts/a.vim/master/plugin/a.vim
cp "${ec_src}/vim/plugin/a.vim" "${ec_dir}/vim/plugin/a.vim" || exit 1
# https://raw.github.com/wonder-mice/vim-whereami/master/plugin/whereami.vim
cp "${ec_src}/vim/plugin/whereami.vim" "${ec_dir}/vim/plugin/whereami.vim" || exit 1
# https://github.com/scala/scala-dist/tree/master/tool-support/src/vim
cp "${ec_src}/vim/syntax/scala.vim" "${ec_dir}/vim/syntax/scala.vim" || exit 1
# https://github.com/vim-jp/cpp-vim
cp "${ec_src}/vim/syntax/c.vim" "${ec_dir}/vim/syntax/c.vim" || exit 1
cp "${ec_src}/vim/syntax/cpp.vim" "${ec_dir}/vim/syntax/cpp.vim" || exit 1
# https://github.com/kana/vim-filetype-haskell/blob/master/indent/haskell.vim
cp "${ec_src}/vim/indent/haskell.vim" "${ec_dir}/vim/indent/haskell.vim" || exit 1
# https://github.com/Keithbsmiley/swift.vim
cp "${ec_src}/vim/indent/swift.vim" "${ec_dir}/vim/indent/swift.vim" || exit 1
cp "${ec_src}/vim/syntax/swift.vim" "${ec_dir}/vim/syntax/swift.vim" || exit 1
# https://github.com/Kitware/CMake/tree/master/Auxiliary
cp "${ec_src}/vim/indent/cmake.vim" "${ec_dir}/vim/indent/cmake.vim" || exit 1
cp "${ec_src}/vim/syntax/cmake.vim" "${ec_dir}/vim/syntax/cmake.vim" || exit 1
# https://github.com/kergoth/vim-bitbake
cp "${ec_src}/vim/syntax/bitbake.vim" "${ec_dir}/vim/syntax/bitbake.vim" || exit 1
# configs
ec_get_docs "${ec_src}/vim/vimrc"
cp "${ec_src}/vim/vimrc" "${ec_dir}/vim/vimrc" || exit 1
ec_get_docs "${ec_src}/vim/filetype.vim"
cp "${ec_src}/vim/filetype.vim" "${ec_dir}/vim/filetype.vim" || exit 1
# vim - setup
"${ec_src}/vim/vimrc-setup" || exit 1
# vim - source
ec_append_init_script "${ec_src}/vim/vimrc-init" ~/.vimrc
# git
mkdir -p "${ec_dir}/git" || exit 1
ec_get_docs "${ec_src}/git/gitconfig"
cp "${ec_src}/git/gitconfig" "${ec_dir}/git/gitconfig" || exit 1
ec_append_init_script "${ec_src}/git/gitconfig-init" ~/.gitconfig
# gdb
mkdir -p "${ec_dir}/gdb" || exit 1
ec_get_docs "${ec_src}/gdb/gdbinit"
cp "${ec_src}/gdb/gdbinit" "${ec_dir}/gdb/gdbinit" || exit 1
ec_append_init_script "${ec_src}/gdb/gdbinit-init" ~/.gdbinit
# tools
mkdir -p "${ec_dir}/bin" || exit 1
ec_get_docs "${ec_src}/tools/x"
cp "${ec_src}/tools/x" "${ec_dir}/bin/x" || exit 1
ec_get_docs "${ec_src}/tools/getpassword"
cp "${ec_src}/tools/getpassword" "${ec_dir}/bin/getpassword" || exit 1
ec_get_docs "${ec_src}/tools/ctags-gen"
cp "${ec_src}/tools/ctags-gen" "${ec_dir}/bin/ctags-gen" || exit 1
# remove backup
rm -rf "${ec_dir_backup}"
fi
echo "Done!"