-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashrc
More file actions
401 lines (333 loc) Β· 9.62 KB
/
bashrc
File metadata and controls
401 lines (333 loc) Β· 9.62 KB
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# ***DO THIS ON NEW MACHINE***
# cd $HOME
# git clone https://github.com/monarin/goodstuffs
# In system bashrc, add
# [ -f "$HOME/goodstuffs/bashrc" ] && . "$HOME/goodstuffs/bashrc"
# [ -f "$HOME/goodstuffs/bashrc_history" ] && . "$HOME/goodstuffs/bashrc_history"
alias viper="ssh -YAC mu238@viper.lbl.gov"
alias dials="ssh -YAC mu238@dials.lbl.gov"
alias pslogin="ssh -YAC monarin@pslogin.slac.stanford.edu"
alias psdev="ssh -YAC monarin@psdev.slac.stanford.edu"
alias atbfs3="ssh monarin@atbfs3.stanford.edu"
alias moje="ssh mojeprot@mojeprotocol.com"
alias cori="ssh -Y monarin@cori.nersc.gov"
alias oakr="ssh -YAC monarin@home.ccs.ornl.gov"
alias smdev="ssh monarin@summitdev.ccs.ornl.gov"
alias s3df="ssh s3dflogin.slac.stanford.edu"
alias frontier="ssh monarin@frontier.olcf.ornl.gov"
alias crusher="ssh monarin@crusher.olcf.ornl.gov"
alias ascent="ssh monarin@login1.ascent.olcf.ornl.gov"
alias perlmutter="ssh monarin@perlmutter-p1.nersc.gov"
alias tmodaq="ssh -YC tmo-daq -l tmoopr"
alias rixdaq="ssh -YC rix-daq -l rixopr"
alias mcclogin="ssh mcclogin.slac.stanford.edu"
alias lclssrv="ssh acclegr@lcls-srv01"
alias ll='ls -l'
alias delpyc="find . -name \"*. pyc\" -delete"
alias now='date "+%Y-%m-%d+%H%M%S"'
export DAQ_LOG_DIR=/sdf/data/lcls/ds/prj/prjdat21/results/appdata/daq_logs.db
export OMPI_MCA_osc=sm # For MPI.Win.Allocate_shared
vman() {
man "$@" | col -b | vi -R -
}
sve() {
DESTPATH="${HOME}/Save/$@_`now`"
echo "Saved to $DESTPATH"
cp -a $@ $DESTPATH
}
gdbpy() {
gdb `which python`
}
mypath() {
MYPATH=$HOME
if [ "$1" != '' ]; then
MYPATH=$@
fi
}
gccthis() {
gcc -pthread -B /reg/g/psdm/sw/conda2/inst/envs/ps-0.0.6/compiler_compat -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/reg/g/psdm/sw/conda2/inst/envs/ps-0.0.6/lib/python3.5/site-packages/numpy/core/include -I/reg/neh/home/monarin/lcls2/install/include -I/reg/g/psdm/sw/conda2/inst/envs/ps-0.0.6/include/python3.5m -c ringbuf.cc -o ringbuf -std=c++11
}
prof_py() {
python -m cProfile -s tottime $1
}
prof_strace_py() {
strace -ttt -f -o $$.log python $1
}
prof_perf_py() {
perf record python $1
echo "run perf report to see results"
}
pyver() {
pyver=$(python -c "import sys; print(str(sys.version_info.major)+'.'+str(sys.version_info.minor))")
echo $pyver
}
export EDITOR=vim
export GIT_EDITOR=vim
# Enable tab completion
source $HOME/goodstuffs/git-completion.bash
# colors!
green="\[\033[0;32m\]"
blue="\[\033[0;34m\]"
purple="\[\033[0;35m\]"
cyan="\[\033[0;36m\]"
reset="\[\033[0m\]"
# Change command prompt
source $HOME/goodstuffs/git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=1
# '\u' adds the name of the current user to the prompt
# '\$(__git_ps1)' adds git-related stuff
# '\W' adds the name of the current directory
myprompt=""
export PS1="$purple\u$cyan@\h$green\$(__git_ps1)$blue \W $myprompt$reset"
grr() {
# -I ignores binary files
grep -I --exclude \*.class --exclude \*.pyc --exclude-dir .git --exclude-dir .svn -r "$@"
}
cutniq() {
grep -v 'Binary file' | cut -d: -f1 | uniq
}
see_disk_quota() {
df -h $HOME
}
see_kerberos_cred() {
klist
}
see_dir_total() {
du -shc ./*
}
git_aa() {
mod_files=($(git status | grep modified: | gawk '{ print $2}'))
length=${#mod_files[@]}
for ((i=0; i<length; i++))
do
echo "adding $i: '${mod_files[i]}'"
git add ${mod_files[i]}
done
}
git_set_remote_ssh() {
git remote set-url origin git@github.com:monarin/$1.git
}
docker_clean() {
arr=( $(docker images | grep "<none>" | gawk '{ print $3 }') )
for imgid in ${arr[*]}
do
printf "remove %s\n" $imgid
docker rmi -f $imgid
done
}
rm_swp() {
arr=( $(find . -name "*.swp") )
for fname in ${arr[*]}
do
printf "remove %s\n" $fname
rm $fname
done
}
sve_git_aa() {
mod_files=($(git status | grep modified: | gawk '{ print $3}'))
length=${#mod_files[@]}
for ((i=0; i<length; i++))
do
f_basename="$(basename "${mod_files[i]}")"
f_dirname="$(dirname "${mod_files[i]}")"
echo "saving $i: '${mod_files[i]}' to ~/Save"
pushd $f_dirname
sve $f_basename
popd
done
}
lstoday() {
ls "$@" -al --time-style=+%D | grep $(date +%D)
}
sacctj() {
sacct -j "$1" --format=JobIDRaw,JobName%12,NodeList%75,Start,End,Elapsed,REQCPUS,ALLOCTRES%25
}
psf() {
ps -p $1 -o pid,vsz=MEMORY -o user,group=GROUP -o cls,pri,rtprio -o comm,args=ARGS | cat
}
sinfof() {
sinfo -o "%30N %10c %10m %35f %10G "
}
sqf() {
squeue $@ -o "%.18i %15j %.8u %.8T %20S %.10M %.6D %R"
}
prc(){
isort "$@"
black "$@"
ruff check "$@"
#flake8 "$@"
}
open_latest() {
local file
prefix=${1}
file=$(ls -t ${prefix} 2>/dev/null | head -n 1)
echo "open_latest $file"
if [[ -n "$file" ]]; then
vim "$file"
else
echo "No ${prefix} files found." >&2
fi
}
tail_latest() {
local file
prefix=${1}
file=$(ls -t ${prefix} 2>/dev/null | head -n 1)
echo "tail_latest $file"
if [[ -n "$file" ]]; then
tail -f "$file"
else
echo "No ${prefix} files found." >&2
fi
}
pip_who_needs() {
if [ -z "$1" ]; then
echo "Usage: pip_who_needs <package-name>"
return 1
fi
local target="$1"
echo "π Checking which user-installed packages require '$target'..."
pip list --user --format=freeze | cut -d= -f1 | while read pkg; do
deps=$(pip show "$pkg" | awk -F': ' '/Requires:/ {print $2}')
if echo "$deps" | grep -wq "$target"; then
echo "π¦ $pkg depends on $target"
fi
done
}
# Function to enable pyenv only when needed
use_pyenv() {
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv >/dev/null 2>&1; then
eval "$(pyenv init -)"
echo "pyenv initialized."
echo "Available versions:"
pyenv versions
else
echo "pyenv not found in $PYENV_ROOT. Please install it first."
fi
}
kill_matching_procs() {
local keyword=$1
if [[ -z "$keyword" ]]; then
echo "Usage: kill_matching_procs <keyword>"
return 1
fi
local pids
pids=$(pgrep -f "$keyword")
if [[ -z "$pids" ]]; then
echo "No matching processes found for: $keyword"
return 0
fi
echo "Killing the following processes matching '$keyword':"
ps -fp $pids
kill $pids
}
ssh_ipmi_tunnel() {
# Usage:
# ssh_ipmi_tunnel local_port ipmi_host ssh_host
local local_port="$1" # e.g. 8787
local ipmi_host="$2" # e.g. drp-srcf-cmp005-ipmi
local ssh_host="$3" # e.g. psbuildrc
echo "π Forwarding $local_port β $ipmi_host:80 via $ssh_host"
ssh -N -L "${local_port}:${ipmi_host}:80" "$ssh_host"
}
# Refresh SSH key on jump host
fix_ssh_key() {
local key="${1:-$HOME/.ssh/id_ed25519}"
local pub="${key}.pub"
local user="monarin"
local host="jump.slac.stanford.edu"
if [[ ! -f "$key" || ! -f "$pub" ]]; then
echo "β Key or pubkey not found: $key / $pub"
return 1
fi
echo "π Adding $key to ssh-agent..."
ssh-add "$key" || return 1
echo "π€ Copying public key to $user@$host..."
ssh-copy-id -i "$pub" "$user@$host" || return 1
echo "β
SSH key refreshed on $host. Try again with: ssh psbuildrc"
}
grx() {
if [ -z "$1" ]; then
echo "Usage: grepexact <pattern> [directory]"
return 1
fi
local pattern="$1"
local dir="${2:-.}"
grep -R --exclude-dir={.git,__pycache__} --include='*.py' -n --color=always "\b${pattern}\b" "$dir"
}
use_gpuio311() {
export MAMBA_ROOT_PREFIX="$HOME/micromamba"
eval "$($HOME/bin/micromamba shell hook -s bash)"
micromamba activate gpuio311
}
activate_xtcpp() {
local xtcpp_root="$HOME/sw/xtcpp/install"
if [ ! -d "$xtcpp_root" ]; then
echo "xtcpp install not found at $xtcpp_root" >&2
return 1
fi
export PYTHONPATH="$xtcpp_root/lib/python3.9/site-packages${PYTHONPATH:+:$PYTHONPATH}"
export PATH="$xtcpp_root/bin:$PATH"
}
detnames_all_streams () {
local exp="$1"
local run="$2"
local base="${3:-/sdf/data/lcls/ds}"
if [[ -z "$exp" || -z "$run" ]]; then
echo "Usage: detnames_all_streams <exp> <runnum> [basepath]" >&2
echo " ex: detnames_all_streams mfx101344525 75" >&2
return 2
fi
# Decode exp like mfx101344525 -> instr=mfx, expdir=mfx/mfx101344525
local instr="${exp:0:3}"
local expdir="${instr}/${exp}"
# Format run rNNNN (4 digits)
local rtag
rtag=$(printf "r%04d" "$run") || return 2
local xtcdir="${base%/}/${expdir}/xtc"
local prefix="${exp}-${rtag}"
# Only chunk 0: ...-c000.xtc2
ls -1 "${xtcdir}/${prefix}-s"*-c000.xtc2 2>/dev/null \
| sed -n 's/.*-s\([0-9]\+\)-c000\.xtc2$/\1 &/p' \
| sort -n -k1,1 \
| cut -d' ' -f2- \
| while IFS= read -r f; do
echo "==> $f"
detnames "$f"
done
}
srun_alloc() {
local jobid="$1"
local node="$2"
if [[ -z "$jobid" || -z "$node" ]]; then
echo "usage: srun_alloc <jobid> <nodename>"
return 1
fi
srun --jobid="$jobid" --nodelist="$node" --pty bash -l
}
weka_tier() {
if [ $# -lt 1 ]; then
echo "Usage: weka_tier <path>" >&2
return 1
fi
weka fs tier location "$@"
}
opencode ()
{
local bin_dir="/sdf/group/lcls/ds/dm/apps/dev/code/.opencode/bin";
local config_dir="/sdf/group/lcls/ds/dm/apps/dev/opencode";
if [[ "$1" == "--local" ]]; then
shift;
bin_dir="$HOME/.opencode/bin";
config_dir="$HOME/.config/opencode";
fi;
OPENCODE_CONFIG_DIR="$config_dir" PATH="$bin_dir:$PATH" command opencode "$@"
}
sq() {
if [ $# -eq 0 ]; then
squeue -u "$USER"
else
squeue "$@"
fi
}