-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy-contents-to-shell-rc.sh
39 lines (38 loc) · 1.16 KB
/
copy-contents-to-shell-rc.sh
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
auto-conda-activate() {
# Automatically detect and use the right shell hook
case "$SHELL" in
*/zsh) eval "$(conda shell.zsh hook 2> /dev/null)" ;;
*/bash) eval "$(conda shell.bash hook 2> /dev/null)" ;;
*) echo "Unsupported shell $SHELL"; return 1 ;;
esac
if [ $# -eq 0 ]; then
if ENV_FILE=$(ls environment.y{a,}ml 2>/dev/null | head -1); then
if [ ! -r "$ENV_FILE" ]; then
echo "Cannot read $ENV_FILE"
return 1
fi
ENV_NAME=$(awk '/^name:/ {print $2}' "$ENV_FILE")
if [ -z "$ENV_NAME" ]; then
echo "No environment name found in $ENV_FILE"
return 1
fi
conda activate "$ENV_NAME"
else
conda activate
fi
elif [ -f "$1" ]; then
if [ ! -r "$1" ]; then
echo "Cannot read $1"
return 1
fi
ENV_NAME=$(awk '/^name:/ {print $2}' "$1")
if [ -z "$ENV_NAME" ]; then
echo "No environment name found in $1"
return 1
fi
conda activate "$ENV_NAME"
else
conda activate "$@"
fi
}
alias 'aca'='auto-conda-activate'