-
Notifications
You must be signed in to change notification settings - Fork 0
/
conda.sh
109 lines (90 loc) · 2.64 KB
/
conda.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
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
_CONDA_EXE="/opt/conda/bin/conda"
_CONDA_ROOT="/opt/conda"
_conda_set_vars() {
# set _CONDA_SHELL_FLAVOR
if [ -n "${BASH_VERSION:+x}" ]; then
_CONDA_SHELL_FLAVOR=bash
elif [ -n "${ZSH_VERSION:+x}" ]; then
_CONDA_SHELL_FLAVOR=zsh
elif [ -n "${KSH_VERSION:+x}" ]; then
_CONDA_SHELL_FLAVOR=ksh
elif [ -n "${POSH_VERSION:+x}" ]; then
_CONDA_SHELL_FLAVOR=posh
else
# default to dash; if we run into a problem here, please raise an issue
_CONDA_SHELL_FLAVOR=dash
fi
if [ -z "${_CONDA_EXE+x}" ]; then
if [ -n "${_CONDA_ROOT:+x}" ]; then
# typically this should be for dev only; _CONDA_EXE should be written at top of file
# for normal installs
_CONDA_EXE="$_CONDA_ROOT/conda/shell/bin/conda"
fi
if ! [ -f "${_CONDA_EXE-x}" ]; then
_CONDA_EXE="$PWD/conda/shell/bin/conda"
fi
fi
# We're not allowing PS1 to be unbound. It must at least be set.
# However, we're not exporting it, which can cause problems when starting a second shell
# via a first shell (i.e. starting zsh from bash).
if [ -z "${PS1+x}" ]; then
PS1=
fi
}
_conda_hashr() {
case "$_CONDA_SHELL_FLAVOR" in
zsh) \rehash;;
posh) ;;
*) \hash -r;;
esac
}
_conda_activate() {
if [ -n "${CONDA_PS1_BACKUP:+x}" ]; then
# Handle transition from shell activated with conda <= 4.3 to a subsequent activation
# after conda updated to >= 4.4. See issue #6173.
PS1="$CONDA_PS1_BACKUP"
\unset CONDA_PS1_BACKUP
fi
\local ask_conda
ask_conda="$(PS1="$PS1" $_CONDA_EXE shell.posix activate "$@")" || \return $?
\eval "$ask_conda"
_conda_hashr
}
_conda_deactivate() {
\local ask_conda
ask_conda="$(PS1="$PS1" $_CONDA_EXE shell.posix deactivate "$@")" || \return $?
\eval "$ask_conda"
_conda_hashr
}
_conda_reactivate() {
\local ask_conda
ask_conda="$(PS1="$PS1" $_CONDA_EXE shell.posix reactivate)" || \return $?
\eval "$ask_conda"
_conda_hashr
}
conda() {
if [ "$#" -lt 1 ]; then
$_CONDA_EXE
else
\local cmd="$1"
shift
case "$cmd" in
activate)
_conda_activate "$@"
;;
deactivate)
_conda_deactivate "$@"
;;
install|update|uninstall|remove)
$_CONDA_EXE "$cmd" "$@" && _conda_reactivate
;;
*)
$_CONDA_EXE "$cmd" "$@"
;;
esac
fi
}
_conda_set_vars
if [ -z "${CONDA_SHLVL+x}" ]; then
\export CONDA_SHLVL=0
fi