-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbashrc
319 lines (257 loc) · 7.31 KB
/
bashrc
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
export TWINE_USERNAME=__token__
# Set the limit of open files to be a high number.
ulimit -n 10240
# Use the github token if available
if [ -f ~/.gh_token ]; then
source ~/.gh_token
fi
function prep-release {
repo=$1
target="/tmp/$1-$(openssl rand -hex 12)"
mkdir -p $target
git clone [email protected]:$1.git $target
tmp-env
pip install build twine
cd $target
}
function clean-jlab {
git clean -dfx
pip install -v -U -e .
jlpm run build
bell
}
# Change to Python's site-packages directory.
function cdsite {
cd "$(python -c "import site; print(site.getsitepackages()[0])")"
}
# Change to the directory for a given python module
function cdpy {
cd "$(python -c "from importlib.util import find_spec; import os; print(find_spec('$1').submodule_search_locations[0])")" 2>/dev/null || cd "$(python -c "import imp, os; print(os.path.dirname(imp.find_module('$1')[1]))")"
}
function edit {
code $@ || gedit $@ &
}
function py-tag {
git pull
pip install pipx
local version=$(pipx run hatch version || pipx run tbump current-version)
git commit -a -m "Release $version"
git tag -a $version -m "$version"; true;
git push --all
git push --tags
}
function py-release {
rm -rf dist build
pip install pipx
pipx run build .
py-tag
pipx run twine check dist/* && pipx run twine upload dist/*
bell
}
# aliases
alias u='cd ..;'
alias ll='ls -lGh'
alias la='ls -aG'
alias ls='ls -aG'
alias ..='cd ..'
alias ...='cd ../..'
alias ws="cd ~/workspace && ls -ltr"
alias jp='cd ~/workspace/jupyter && ls -ltr'
alias jpa='cd ~/workspace/jupyter/admin && ls -ltr'
alias dot='cd ~/workspace/dotfiles'
alias hub='jupyterhub'
alias octave='octave-cli'
alias bel='tput bel'
alias gs='git status'
alias gsv='git status --verbose'
alias gpo='git push origin'
alias gu='git pull upstream'
alias gb="git for-each-ref --sort='-authordate:iso8601' --format=' %(authordate:relative)%09%(refname:short)' refs/heads | tail -r"
alias gd='git diff'
alias ga='git add'
alias gc='git commit --verbose'
alias gr='git remote -v'
alias gprb='git pull --rebase'
alias gnvm="git reset --soft HEAD~1"
alias run-in-docker="docker run -it -v $(pwd):/usr/src/project jupyter/minimal-notebook:latest /bin/bash"
alias el="ls $HOME/workspace/.venvs"
alias pymongo="workon mongo-python-driver"
alias mongoarrow="workon mongo-arrow"
alias motor="workon motor"
export DRIVERS_TOOLS=
alias run-server="$HOME/workspace/drivers-evergreen-tools/.evergreen/docker/run-server.sh"
alias python3.8 'uv run --python=3.8 python3'
alias python3.9 'uv run --python=3.9 python3'
alias python3.10 'uv run --python=3.10 python3'
alias python3.11 'uv run --python=3.11 python3'
alias python3.12 'uv run --python=3.12 python3'
alias python3.13 'uv run --python=3.13 python3'
alias python3 python3.12
export TMPDIR='/tmp'
export PATH="$HOME/bin:$PATH"
alias search="git --no-pager grep -i -n"
alias searchsensitive="git --no-pager grep -n"
function ea() {
source $HOME/.venvs/$1/bin/activate
}
function bell() {
tput bel
say "I finished that long thing I did" 2>/dev/null
}
unalias gca 2>/dev/null
function gca() {
# Allow for pre-commit auto-fixes.
git commit -a -m "${@: -1}" || git commit -a -m "${@: -1}"
}
function gpa() {
# get to the last arg in case we accidently include -m
gca $@ && git push origin
}
function get_default_branch() {
git remote show upstream | grep 'HEAD branch' | cut -d' ' -f5
}
function gn() {
branch=${2:-$(get_default_branch)}
gupdate ${branch}
git checkout -b "$1" upstream/${branch}
bell
}
unalias grb 2>/dev/null
function grb() {
branch=${1:-$(get_default_branch)}
git fetch upstream ${branch}
git rebase -i upstream/${branch}
}
function gpr() {
git checkout $(get_default_branch)
git branch -D pr/$1 2>/dev/null
git fetch upstream pull/$1/head:pr/$1
git checkout pr/$1
bell
}
function gprelease() {
git fetch upstream prerelease
git checkout -b "$1" upstream/prerelease
}
function gprune() {
default_branch=$(get_default_branch)
git co ${default_branch}
git fetch origin
git fetch upstream
# remove PR branches
git branch | grep pr\/ | xargs -n 1 git branch -D
# remove local merged branches
git branch --merged upstream/${default_branch} | sed 's/\*/ /' | grep -v ${default_branch} | xargs -n 1 git branch -d
# remove remote merged branches
git branch -r --merged upstream/${default_branch} | grep 'origin/' | grep -v ${default_branch} | grep -v gh-pages | sed 's/origin\///' | xargs -n 1 git push --delete origin --no-verify
bell
}
function gdel() {
default_branch=$(get_default_branch)
git co ${default_branch}
for var in "$@"
do
git branch -D "$var"
git push origin ":$var"
done
bell
}
function gdeltag() {
git tag -d $1
git push --delete origin $1
}
function gclone() {
local user=$(git config github.user)
git clone [email protected]:$user/$2 || return 1
cd $2
git remote add upstream [email protected]:$1/$2.git
default_branch=$(get_default_branch)
git pull upstream ${default_branch} -X theirs
bell
}
function gclonea() {
git clone [email protected]:$1/$2 || return 1
cd $2
git remote add upstream [email protected]:$1/$2.git
default_branch=$(get_default_branch)
git pull upstream ${default_branch}
bell
}
function gupdate() {
local current=$(git branch --show-current)
local default=$(get_default_branch)
local target=${1:-$default}
local dirty="false"
if [[ $(git diff --stat) != '' ]]; then
dirty="true"
git stash
fi
git fetch origin $target
git checkout $target
git pull upstream $target -X theirs
git push origin $target --no-verify -f
git checkout $current
if [[ ${dirty} == "true" ]]; then
git stash apply
fi
}
unalias gra 2>/dev/null
function gra {
if [[ $# -ne 1 ]]; then
echo "Specify user"
fi
local name=$1
if [[ $# -eq 2 ]]; then
name=$2
fi
local upstream=$(git remote get-url upstream)
local repo=$(basename $upstream .git)
git remote add $name [email protected]:$1/$repo
git fetch $name
bell
}
tmp-conda() {
local name="$(openssl rand -hex 12)"
conda create -y -p /tmp/conda_envs/${name} python=3.10 pipx
conda activate /tmp/conda_envs/${name}
bell
}
tmp-env() {
local name="$(openssl rand -hex 12)"
mkdir -p /tmp/venvs/$name
cd /tmp/venvs/$name
uv venv --seed --python 3.8
source .venv//bin/activate
bell
}
workon() {
local name=$1
if [ ! -d $HOME/workspace/$name ];
then
echo "ERROR: \"$HOME/workspace/$name\" not found!"
return 1
fi
cd ~/workspace/$name
if [ ! -f .envrc ]; then
echo "test -d .venv || uv venv --seed --python 3.8" > .envrc
echo "source .venv/bin/activate" >> .envrc
direnv allow .
fi
}
alias wo=workon
edit() {
local curpath=$(pwd)
while [ ! -d "$curpath/.git" ]
do
curpath=$(dirname ${curpath})
done
code $curpath
}
tmp-conda-full() {
local name="$(openssl rand -hex 12)"
conda create -y -p /tmp/conda_envs/${name} notebook python=3.10 ipdb pipx
conda activate /tmp/conda_envs/${name}
bell
}
alias ubuntu="docker run -it -e GRANT_SUDO=yes --user root jupyter/minimal-notebook bash"
export PROMPT_COMMAND='echo'