Created
September 27, 2024 22:03
-
-
Save z-a-f/116b4d93fa4e7399c0e5dfcfa24a917c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
realpath() { | |
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}" | |
} | |
layout_micromamba() { | |
# Setup | |
env_vars_required MAMBA_ROOT_PREFIX MAMBA_EXE | |
__shell=$(basename $SHELL) | |
__mamba_setup="$("$MAMBA_EXE" shell hook --shell "$__shell" --root-prefix "$MAMBA_ROOT_PREFIX" 2> /dev/null)" | |
if [ $? -eq 0 ]; then | |
eval "$__mamba_setup" | |
micromamba activate $@ | |
else | |
# Fallback on help from mamba activate | |
${MAMBA_EXE} activate $@ | |
fi | |
unset __mamba_setup | |
unset __shell | |
unset PS1 | |
} | |
layout_anaconda() { | |
env_vars_required CONDA_HOME | |
local ACTIVATE="${CONDA_HOME}/bin/activate" | |
if [ -n "$1" ]; then | |
# Explicit environment name from layout command. | |
local env_name="$1" | |
source $ACTIVATE ${env_name} | |
elif (grep -q name: environment.yml); then | |
# Detect environment name from `environment.yml` file in `.envrc` directory | |
source $ACTIVATE `grep name: environment.yml | sed -e 's/name: //' | cut -d "'" -f 2 | cut -d '"' -f 2` | |
else | |
(>&2 echo No environment specified); | |
exit 1; | |
fi; | |
unset PS1 | |
} | |
layout_micro() { | |
layout micromamba $@ | |
} | |
layout_conda() { | |
if has conda; then | |
layout anaconda $@ | |
else | |
layout micromamba $@ | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment