-
Notifications
You must be signed in to change notification settings - Fork 37
/
.shellrc
296 lines (233 loc) · 7.35 KB
/
.shellrc
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#!/usr/bin/env zsh
# vim:filetype=zsh syntax=zsh tabstop=2 shiftwidth=2 softtabstop=2 expandtab autoindent fileencoding=utf-8
################################################################################
# This file is sourced only for login shells. It is used to define the bare
# minimum shell functions and env vars that are needed during bootstrap of a
# vanilla OS to bootstrap installation of all other config files.
#
# file location: ${HOME}/.shellrc
# load order: .zshenv [.shellrc], .zshrc [.shellrc, .aliases [.shellrc]], .zlogin
################################################################################
# execute 'FIRST_INSTALL=true zsh' to debug the load order of the custom zsh configuration files
test -n "${FIRST_INSTALL+1}" && echo "loading ${0}"
export LANG='en_US.UTF-8'
export LANGUAGE='en_US.UTF-8'
export LC_COLLATE='en_US.UTF-8'
export LC_CTYPE='en_US.UTF-8'
export LC_MESSAGES='en_US.UTF-8'
export LC_MONETARY='en_US.UTF-8'
export LC_NUMERIC='en_US.UTF-8'
export LC_TIME='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'
export LESSCHARSET='utf-8'
export ZDOTDIR="${ZDOTDIR:-${HOME}}"
export XDG_CACHE_HOME="${HOME}/.cache"
export XDG_CONFIG_HOME="${HOME}/.config"
export XDG_DATA_HOME="${HOME}/.local/share"
export XDG_STATE_HOME="${HOME}/.local/state"
# Moving homebrew env vars here itself so that the initial homebrew installation on a vanilla OS can be done/applied into memory immediately
export ARCH="$(uname -m)"
export ARCHFLAGS="-arch ${ARCH}"
if [[ "${ARCH}" =~ 'arm' ]]; then
export HOMEBREW_PREFIX='/opt/homebrew'
else
export HOMEBREW_PREFIX='/usr/local'
fi
export HOMEBREW_NO_ANALYTICS=1
export HOMEBREW_CLEANUP_MAX_AGE_DAYS=3
export HOMEBREW_CLEANUP_PERIODIC_FULL_DAYS=3
export HOMEBREW_BAT=1
export HOMEBREW_VERBOSE_USING_DOTS=1
export HOMEBREW_BUNDLE_FILE="${HOME}/Brewfile"
# TODO: Uncomment once this feature is stabilized
# export HOMEBREW_VERIFY_ATTESTATIONS=1
# Note: Change these as per your settings. Deleting them will essentially unset the var(s) and thus any aliases/backup-operations/etc will not be processed for those deleted variable(s)
# ------------ Env vars for basic/common setup ------------
# The github username where the setup scripts are downloaded from
export GH_USERNAME='vraravam'
# Vijay's github username for setting upstream remote
export UPSTREAM_GH_USERNAME='vraravam' # Note: Do NOT change this
# This repo is cloned into this location
export DOTFILES_DIR="${HOME}/.bin-oss"
# Branch name of the dotfiles repo that's to be used for testing PR changes before merging
export DOTFILES_BRANCH='master'
# All development codebases are cloned into a subfolder of this folder
export PROJECTS_BASE_DIR="${HOME}/dev"
# Executable scripts that are not shared as part of this public repo are present here
export PERSONAL_BIN_DIR="${HOME}/personal/dev/bin"
# Many configuration files (eg `.envrc`, `.tool-versions`), that might contain sensitive info and so cannot be committed into those repos are stored here and symlinked to their target destination
export PERSONAL_CONFIGS_DIR="${HOME}/personal/dev/configs"
# All browser profiles are captured in this folder (might contain sensitive info like browsing history and so is considered private)
export PERSONAL_PROFILES_DIR="${HOME}/personal/$(whoami)/profiles"
# Keybase username
export KEYBASE_USERNAME='avijayr'
# Keybase home repo name
export KEYBASE_HOME_REPO_NAME='home'
# Keybase profiles repo name
export KEYBASE_PROFILES_REPO_NAME='profiles'
# -----------------------------------------------------
colorize() {
printf "\x1b[${1}m"
}
NC=$(colorize '0') # No Color
BLACK=$(colorize '0;30')
DARK_GRAY=$(colorize '1;30')
RED=$(colorize '0;31')
LIGHT_RED=$(colorize '1;31')
GREEN=$(colorize '0;32')
LIGHT_GREEN=$(colorize '1;32')
ORANGE=$(colorize '0;33')
YELLOW=$(colorize '1;33')
BLUE=$(colorize '0;34')
LIGHT_BLUE=$(colorize '1;34')
PURPLE=$(colorize '0;35')
LIGHT_PURPLE=$(colorize '1;35')
CYAN=$(colorize '0;36')
LIGHT_CYAN=$(colorize '1;36')
LIGHT_GRAY=$(colorize '0;37')
WHITE=$(colorize '1;37')
blue() {
printf "${BLUE}${1}${NC}"
}
light_blue() {
printf "${LIGHT_BLUE}${1}${NC}"
}
purple() {
printf "${PURPLE}${1}${NC}"
}
light_purple() {
printf "${LIGHT_PURPLE}${1}${NC}"
}
cyan() {
printf "${CYAN}${1}${NC}"
}
light_cyan() {
printf "${LIGHT_CYAN}${1}${NC}"
}
green() {
printf "${GREEN}${1}${NC}"
}
light_green() {
printf "${LIGHT_GREEN}${1}${NC}"
}
red() {
printf "${RED}${1}${NC}"
}
light_red() {
printf "${LIGHT_RED}${1}${NC}"
}
yellow() {
printf "${YELLOW}${1}${NC}"
}
warn() {
echo "$(yellow "**WARN** ${1}")"
}
success() {
echo "$(green "**SUCCESS** ${1}")"
}
debug() {
warn "${1}"
echo "${PATH}"
}
error() {
echo "$(red "${1}")"
exit 1
}
section_header() {
echo "$(blue '==>') $(purple "${1}")"
}
is_non_zero_string() {
! test -z "${1}"
}
is_file() {
is_non_zero_string "${1}" && test -f "${1}"
}
is_executable() {
is_non_zero_string "${1}" && test -e "${1}"
}
is_directory() {
is_non_zero_string "${1}" && test -d "${1}"
}
dir_has_children() {
is_directory "${1}" && test -n "$(ls -A "${1}")"
}
ensure_dir_exists() {
if is_non_zero_string "${1}"; then
mkdir -p "${1}"
else
warn "Skipping creation of the directory since '${1}' is not defined"
fi
}
is_git_repo() {
is_directory "${1}/.git"
}
load_file_if_exists() {
# shellcheck disable=SC2015
# shellcheck disable=SC1090
is_file "${1}" && source "${1}"
}
delete_directory_if_exists() {
is_directory "${1}" && echo "$(red "Deleting") '$(green "${1}")'" && sudo rm -rf "${1}"
}
command_exists() {
type "${1}" &> /dev/null 2>&1
}
# Note: This function is kind of equivalent to 'omz reload', but that doesn't seem to work when installing on a vanilla OS
load_zsh_configs() {
local file_list=('.zshenv' '.zshrc' '.zlogin')
for file in "${file_list[@]}"; do
load_file_if_exists "${ZDOTDIR}/${file}"
done
}
append_to_path_if_dir_exists() {
is_directory "${1}" && path+="${1}"
}
append_to_fpath_if_dir_exists() {
is_directory "${1}" && fpath+="${1}"
}
prepend_to_path_if_dir_exists() {
is_directory "${1}" && export PATH="${1}:${PATH+:${PATH}}"
}
prepend_to_manpath_if_dir_exists() {
is_directory "${1}" && export MANPATH="${1}:${MANPATH+:${MANPATH}}"
}
prepend_to_ldflags_if_dir_exists() {
is_directory "${1}" && export LDFLAGS="-L${1} ${LDFLAGS+ ${LDFLAGS}}"
}
prepend_to_cppflags_if_dir_exists() {
is_directory "${1}" && export CPPFLAGS="-I${1} ${CPPFLAGS+ ${CPPFLAGS}}"
}
prepend_to_pkg_config_path_if_dir_exists() {
is_directory "${1}" && export PKG_CONFIG_PATH="${1}${PKG_CONFIG_PATH+:${PKG_CONFIG_PATH}}"
}
is_macos() {
[[ "${OSTYPE}" =~ 'darwin' ]]
}
is_linux() {
[[ "${OSTYPE}" =~ 'Linux' ]]
}
is_windows() {
[[ "${OSTYPE}" =~ 'MINGW' ]]
}
keep_sudo_alive() {
section_header 'Keeping sudo alive till this script has finished'
sudo -v
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
}
build_keybase_repo_url() {
echo "keybase://private/${KEYBASE_USERNAME}/${1}"
}
folder_size() {
echo $(cyan "$(\du -sh "${1}" | cut -f1)")
}
# if is_macos; then
# Uninstall and reinstall xcode (useful immediately after upgrade or if reinstalling the OS)
# TODO: Kept for reference purposes
# reinstall_xcode() {
# # delete if already present
# delete_directory_if_exists '/Applications/Xcode.app'
# xcode-select --install
# sudo xcodebuild -license accept -quiet || true
# success 'Successfully installed xcode'
# }
# fi