-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc_user
256 lines (222 loc) · 7.98 KB
/
.bashrc_user
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
#!/usr/bin/env bash
# If new information was added to ~/.profile in this session
# defer to a tmp profile until the next session.
if [ -f /tmp/.profile ]; then
. /tmp/.profile
fi
if [ -f /tmp/.bash_profile ]; then
. /tmp/.bash_profile
fi
# Avoid CVE-2022-24765
# c.f. https://github.blog/2022-04-12-git-security-vulnerability-announced/
export GIT_CEILING_DIRECTORIES="/home"
# Enable .pythonrc.py
if [ -f "${HOME}/.pythonrc.py" ]; then
export PYTHONSTARTUP="${HOME}/.pythonrc.py"
fi
# Ensure that pip can't install outside a virtual environment
if [ ! -f "${HOME}/.config/pip/pip.conf" ]; then
export PIP_REQUIRE_VIRTUALENV=true
fi
# Ensure local virtualenv setup
if [ ! -f "${HOME}/opt/venv/bin/virtualenv" ]; then
curl -sL --location --output /tmp/virtualenv.pyz https://bootstrap.pypa.io/virtualenv.pyz
python3 /tmp/virtualenv.pyz ~/opt/venv
~/opt/venv/bin/pip install --upgrade pip
~/opt/venv/bin/pip install virtualenv
mkdir -p ~/bin # Ensure exists if new machine
ln -s ~/opt/venv/bin/virtualenv ~/bin/virtualenv
fi
# Add pyenv
if [ -d "${HOME}/.pyenv/bin" ]; then
eval "$(pyenv init -)"
# Place pyenv shims on path
if [[ ":${PATH}:" != *":$(pyenv root)/shims:"* ]]; then
eval "$(pyenv init --path)"
fi
if [ -d "${HOME}/.pyenv/plugins/pyenv-virtualenv" ]; then
# Place pyenv-virtualenv shims on path
if [[ ":${PATH}:" != *":$(pyenv root)/plugins/pyenv-virtualenv/shims:"* ]]; then
eval "$(pyenv virtualenv-init -)"
fi
fi
# Allow for prompt updating on venv switch
# c.f. https://github.com/pyenv/pyenv-virtualenv/issues/135#issuecomment-717554081
export PYENV_VIRTUALENV_DISABLE_PROMPT=1
export BASE_PROMPT=$PS1
function updatePrompt {
if [[ "$(pyenv version-name)" != "system" ]]; then
PYENV_VER=$(pyenv version-name) # capture version name in variable
export PS1="(${PYENV_VER%%:*}) "$BASE_PROMPT # grab text prior to first ':' character
else
export PS1=$BASE_PROMPT
fi
}
export PROMPT_COMMAND='updatePrompt'
# default venv
if [ -d "${HOME}/.pyenv/versions/base" ]; then
pyenv activate base
fi
alias deactivate='pyenv deactivate'
fi
# Enable tab completion of Python virtual environments
if [ -f /opt/_venv-activate/_venv-activate.sh ]; then
_VENV_ACTIVATE_HOME="${HOME}/.venvs"
_VENV_ACTIVATE_PYTHON=$(which python3)
. /opt/_venv-activate/_venv-activate.sh
fi
# Enable pipx shell completions
if [ -f "${HOME}/bin/pipx" ]; then
eval "$(register-python-argcomplete pipx)"
fi
# Enable h5ls tab completion
if [ -f /opt/_h5ls/_h5ls.sh ]; then
. /opt/_h5ls/_h5ls.sh
fi
# Add GPG key
export GPG_TTY=$(tty)
# Ensure LD_LIBRARY_PATH exists if application unsets it
if [ -z "${LD_LIBRARY_PATH}" ]; then
LD_LIBRARY_PATH="${_PRESERVE_LD_LIBRARY_PATH}"; export LD_LIBRARY_PATH;
fi
# Ensure EDITOR is set for use by bash's 'edit-and-execute-command'
if [ -z "${EDITOR}" ]; then
export EDITOR="$(command -v vim)"
fi
# User Functions
# c.f. https://gist.github.com/matthewfeickert/498cd93af35b6664caab5dece20342e1
# remember to xhost +
function root-docker () {
local input_path
input_path="${1}"
if [ -z "${input_path}" ]; then
input_path=$(pwd)
fi
if [[ "${input_path}" == "shell" ]]; then
cmd='/bin/bash'
else
if [[ "${input_path::7}" == "root://" ]]; then
# Accessing file over xrootd
file_path="${input_path}"
else
file_path=$(readlink -f ${input_path})
fi
cmd="root -l ${file_path}"
fi
docker run --rm -ti \
-e DISPLAY="${DISPLAY}" \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v /tmp/"krb5cc_$(id -u ${USER})":/tmp/krb5cc_0 \
-v /tmp/:/tmp/ \
-v "${HOME}":"${HOME}" \
atlasamglab/stats-base:root6.24.06 "${cmd}"
}
# c.f.Richard McElreath's 2024-01-26 tweet
# https://twitter.com/rlmcelreath/status/1750807826883027304/
function bibtex-from-doi () {
# Examples:
# bibtex-from-doi 10.21105/joss.02823
# bibtex-from-doi https://doi.org/10.21105/joss.02823
local doi
doi="${1}"
if [ -z "${doi}" ]; then
echo "Please provide a DOI of the form 10.prefix/suffix"
return 1
fi
# check if the doi is actually a url and if so strip of the url part
if [[ "${doi}" == "https://doi.org/"* ]]; then
doi="${doi:16}"
fi
curl --location --header "Accept: application/x-bibtex" "https://doi.org/${doi}"
}
# Utility function for https://github.com/conda-forge/staged-recipes
function build-staged-recipe () {
# Example:
# build-staged-recipe 12
local CPU_COUNT
CPU_COUNT="${1:-10}"
echo "# docker system prune -f && pixi run lint && CPU_COUNT="${CPU_COUNT}" pixi run build-linux linux64"
docker system prune -f
pixi run lint && CPU_COUNT="${CPU_COUNT}" pixi run build-linux linux64
}
# Utility function for setting up ATLAS Athena dev environment
function setup-athena-dev-environment () {
# Example:
# setup-athena-dev-environment --org atlas-asg --repository columnar-athena --branch columnar --fetch-depth 50 --directory debug-columnar-athena
local ORG="atlas"
local REPOSITORY="athena"
local BRANCH="main"
local FETCH_DEPTH=50
local DIRECTORY="${REPOSITORY}"
# Parse command-line arguments
while [[ "$#" -gt 0 ]]; do
case "$1" in
--org|-o)
ORG="$2"
shift 2
;;
--repository|-r)
REPOSITORY="$2"
DIRECTORY="${REPOSITORY}"
shift 2
;;
--branch|-b)
BRANCH="$2"
shift 2
;;
--fetch-depth|-f)
FETCH_DEPTH="$2"
shift 2
;;
--directory|-d)
DIRECTORY="$2"
shift 2
;;
--help|-h)
echo "Usage: setup-athena-dev-environment [OPTIONS]"
echo ""
echo "Options:"
echo " --org, -o Set the CERN GitLab org name (default: atlas)"
echo " --repository, -r Set the repository name (default: athena)"
echo " --branch, -b Set the branch name (default: main)"
echo " --fetch-depth, -f Set the fetch depth (default: 50)"
echo " --directory, -d Set the cloned repository directory name (default: athena)"
echo " --help, -h Show this help message and exit"
return 0
;;
*)
echo "Unknown option: $1"
return 1
;;
esac
done
# Ensure DIRECTORY is set before cleanup
if [[ -z "${DIRECTORY}" ]]; then
echo "Error: Repository name is not set."
return 1
fi
if [ -d "${DIRECTORY}" ]; then
echo -e "\n# rm -rf ${DIRECTORY}"
rm -rf ${DIRECTORY}
fi
if [[ "${REPOSITORY}" != "${DIRECTORY}" ]]; then
echo -e "\n# git clone --no-checkout --depth ${FETCH_DEPTH} --branch ${BRANCH} ssh://git@gitlab.cern.ch:7999/${ORG}/${REPOSITORY}.git ${DIRECTORY}"
else
echo -e "\n# git clone --no-checkout --depth ${FETCH_DEPTH} --branch ${BRANCH} ssh://git@gitlab.cern.ch:7999/${ORG}/${REPOSITORY}.git"
fi
git clone --no-checkout --depth "${FETCH_DEPTH}" --branch ${BRANCH} ssh://git@gitlab.cern.ch:7999/${ORG}/${REPOSITORY}.git "${DIRECTORY}"
echo -e "\n# cd ${DIRECTORY}/"
cd "${DIRECTORY}"
echo -e "\n# git sparse-checkout init --cone"
git sparse-checkout init --cone
echo -e "\n# git sparse-checkout set PhysicsAnalysis Projects Reconstruction"
git sparse-checkout set PhysicsAnalysis Projects Reconstruction
echo -e "\n# git switch ${BRANCH}"
git switch ${BRANCH}
echo -e "\n# cd -"
cd -
}
# Add pixi shell autocompletion
if [ -d "${HOME}/.pixi/bin" ] ; then
eval "$(pixi completion --shell bash)"
fi