-
Notifications
You must be signed in to change notification settings - Fork 2
/
.bash_profile
291 lines (237 loc) · 6.7 KB
/
.bash_profile
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
#!/bin/bash
HISTFILESIZE=100000
HISTSIZE=100000
dice() {
echo $(( $(od -An -N1 </dev/urandom) % ${1:-6} + 1 ))
}
alias g=gvim
alias k=kubectl
alias idea=idea-ultimate
alias pipefox='firefox "data:text/html;base64,$(base64 -w 0 <&0)"'
cfox() {
curl -- "${1}" | pipefox
}
alias htype="locate --regex '\\.c$' | shuf | head -1 | xargs pv -q -L 20"
ccache="/usr/lib/ccache/bin"
PATH="~/bin:~/.dotnet/tools:${PATH}"
old_IFS="$IFS"; IFS=":"; newpath=":"
for i in $PATH; do
[ "$i" != "$ccache" ] || continue
if [ "${i#\~/}" != "${i}" ]; then
i="${HOME}/${i#\~/}"
[ -d "${i}" ] || continue
fi
[ "${newpath}" = "${newpath//:${i}:}" ] || continue
newpath="${newpath}${i}:"
done
IFS="$old_IFS"
PATH="${ccache}${newpath%:}"
export PATH
unset newpath
unset ccache
unset old_IFS
unset i
export GPG_TTY=`tty`
export PIP_RETRIES=20
export PIP_TIMEOUT=60
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export SAM_CLI_TELEMETRY=0
umask 022
declare -A colors=(
["red"]="31"
["green"]="32"
["yellow"]="33"
["blue"]="34"
["cyan"]="36"
["white"]="37"
["reset"]="00"
)
c() {
local bold=
[ "${2}" = bold ] && bold="01;"
echo -e "\033[${bold}${colors["$1"]}m"
}
pc() {
local bold=
[ "${2}" = bold ] && bold="01;"
echo "\[\033[${bold}${colors["$1"]}m\]"
}
t() {
echo -ne "\033]30;"
echo -n "${1}"
echo -ne "\007"
}
parse_git_repo() {
local repo stashc
if git rev-parse --git-dir >/dev/null 2>&1; then
stashc="$(git stash list 2>/dev/null | wc -l)"
if [ ${stashc} = 0 ]; then
stashc=
else
stashc=" [#${stashc}]"
fi
repo="$(git branch 2>/dev/null | sed -n '/^\*/s/^\* //p')"
if git diff --ignore-submodules=dirty --exit-code --quiet 2>/dev/null >&2; then
if git diff --ignore-submodules=dirty --exit-code --cached --quiet 2>/dev/null >&2; then
repo="$(pc green)${repo}$(pc reset)"
else
repo="$(pc cyan)"'!'"${repo}$(pc reset)"
fi
else
repo="$(pc red)"'!'"${repo}$(pc reset)"
fi
if git remote -v | grep -qF /dotfiles.git; then
echo " {${repo}${stashc}}"
else
echo " ${repo}${stashc}"
fi
fi
}
prompt_command() {
PS1="$(pc green bold)\u@\h$(pc blue bold) \w$(pc reset)$(parse_git_repo) $(pc blue bold)\$$(pc reset) "
if [ -n "${VIRTUAL_ENV}" ]; then
PS1="$(pc white bold)($(basename "${VIRTUAL_ENV}") $(pc reset)$(python -V 2>&1 | cut -d ' ' -f2 | cut -d. -f1,2)$(pc white bold))$(pc reset) ${PS1}"
fi
}
PROMPT_COMMAND=prompt_command
PROMPT_DIRTRIM=3
grb() {
local cmd
git fetch
cmd=(
git rebase
origin/$( LC_ALL=C git remote show origin | sed -n "/HEAD branch/s/.*: //p" )
)
echo "$(c white bold)${cmd[*]}$(c reset)"
"${cmd[@]}"
}
alias gst='git status -sb'
alias gbr='git --no-pager branch'
gc() {
local x
git branch -r | grep -v HEAD | while read file; do
git branch -r -d $file
done && git fetch && git gc --prune=now
branch="$(git branch 2>/dev/null | sed -n '/^\*/s/^\* //p')"
for prefix in "$@"; do
git branch -r | grep -F "/${prefix}" | cut -d/ -f2- | while read x; do
git checkout $x
done
done
if [ -n "${branch}" ]; then
git checkout "${branch}"
fi
}
alias fab="venvexec.sh ./ fab"
alias inv="venvexec.sh ./ inv"
_venv_wrapper="$(
wrappers=(
/usr/bin/virtualenvwrapper.sh
/usr/share/virtualenvwrapper/virtualenvwrapper.sh
)
for cand in "${wrappers[@]}"; do
if [ -r "${cand}" ]; then
echo "${cand}"
break
fi
done
)"
if [ -n "${_venv_wrapper}" ]; then
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
. "${_venv_wrapper}"
alias venv='. "$(venvexec.sh . /bin/sh -c '\''echo "${VIRTUAL_ENV}"'\'')/bin/activate"'
# virtualenv aliases
eval "$(
lsvirtualenv -b | while read file; do \
echo "alias ${file}='t "${file}" && workon "${file}"'"; \
done \
)"
fi
[ -r ~/.bash_profile_private ] && . ~/.bash_profile_private
# Directory aliases
eval "$(
for base in "${project_bases[@]}"; do \
( \
ls -1fF -- "${base}" | grep '[@/]' | while read file; do \
case "${file}" in ./|../) continue ;; *@) \
x="$( readlink -- "${base}/${file%?}" )"; \
[ "${x/\/}" = "${x}" ] || continue ;; \
esac; \
x="${file%?}"; \
echo "alias ${x}='t "${x}" && cd "${base}/${x}"'"; \
done; \
) \
done \
)"
# Quick checkout
co() {(
set -eu
name="${1:-}"
if [ -z "${name}" ]; then
exit 1
fi
owner="${default_project_owner}"
cd "${default_project_base}"
git clone "[email protected]:${owner}/${name}.git" "${name}".new
VIRTUAL_ENV=
pushd ~/
rmvirtualenv "${name}"
popd
rm -f -- "${name}"
mv -v -- "${name}".new "${name}"
cd "${name}"
)}
# Python-versioned checkouts and venvs
_project() {(
py="python${1}"
name="${2}"
owner="${3}"
base="${4}"
cd "${base}" || exit 1
dir="$(pwd)"
mkvirtualenv --python "${py}" "${name}"
workon "${name}"
pip install --upgrade pip
cd "${dir}"
git clone "[email protected]:${owner}/${name}.git" "${name}.cloned"
mkdir -p -- "${VIRTUAL_ENV}/src"
mv -v -- "${name}.cloned" "${VIRTUAL_ENV}"/src/"${name}"
(
pdir="$( cd "${VIRTUAL_ENV}" && pwd )"
cd "${dir}"
ln -s "${pdir}"
)
echo "cd '${dir}/${name}/src/${name}'" >> "${VIRTUAL_ENV}"/bin/postactivate
workon "${name}"
pip install -r development.txt
)}
project2() {
_project 2.7 "${1}" "${2:-${default_project_owner}}" "${3:-${default_project_base}}"
}
project3() {
_project 3 "${1}" "${2:-${default_project_owner}}" "${3:-${default_project_base}}"
}
project36() {
_project 3.6 "${1}" "${2:-${default_project_owner}}" "${3:-${default_project_base}}"
}
project37() {
_project 3.7 "${1}" "${2:-${default_project_owner}}" "${3:-${default_project_base}}"
}
project38() {
_project 3.8 "${1}" "${2:-${default_project_owner}}" "${3:-${default_project_base}}"
}
project39() {
_project 3.9 "${1}" "${2:-${default_project_owner}}" "${3:-${default_project_base}}"
}
project310() {
_project 3.10 "${1}" "${2:-${default_project_owner}}" "${3:-${default_project_base}}"
}
project311() {
_project 3.11 "${1}" "${2:-${default_project_owner}}" "${3:-${default_project_base}}"
}
project312() {
_project 3.12 "${1}" "${2:-${default_project_owner}}" "${3:-${default_project_base}}"
}
project313() {
_project 3.13 "${1}" "${2:-${default_project_owner}}" "${3:-${default_project_base}}"
}