Skip to content

Commit ce57588

Browse files
committed
(tue-env)(switch) add persistent option
1 parent cfe692b commit ce57588

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

setup/tue-env.bash

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ Environment directory '${tue_env_dir}' didn't exist (anymore)"""
218218

219219
elif [[ ${cmd} == "switch" ]]
220220
then
221-
local tue_env
221+
local persistent tue_env
222+
persistent="false"
222223
if [[ -z "$1" ]]
223224
then
224225
show_help="true"
@@ -230,6 +231,8 @@ Environment directory '${tue_env_dir}' didn't exist (anymore)"""
230231
show_help="true"
231232
break
232233
;;
234+
--persistent )
235+
persistent="true" ;;
233236
--*)
234237
echo "[tue-env](switch) Unknown option $i"
235238
show_help="true"
@@ -260,6 +263,9 @@ Environment directory '${tue_env_dir}' didn't exist (anymore)"""
260263
tue_env_dir=$(cat "${TUE_DIR}"/user/envs/"${tue_env}")
261264
[[ -d "${tue_env_dir}" ]] || { echo "[tue-env](switch) Environment directory '${tue_env_dir}' (environment '${tue_env}') does not exist"; return 1; }
262265

266+
[[ "${persistent}" == "true" ]] && tue-env set-default "${tue_env}"
267+
268+
# Deactivate the old virtualenv if it exists
263269
[[ -n ${VIRTUAL_ENV} ]] && echo "[tue-env](switch) deactivating old virtualenv" && deactivate
264270

265271
echo "[tue-env](switch) Unsetting all TUE_ENV* of the old environment: '${TUE_ENV}'"
@@ -274,6 +280,7 @@ Environment directory '${tue_env_dir}' didn't exist (anymore)"""
274280
TUE_ENV_DIR=${tue_env_dir}
275281
export TUE_ENV_DIR
276282

283+
echo "[tue-env](switch) Loading the new '${TUE_ENV}' environment"
277284
# shellcheck disable=SC1091
278285
source "$TUE_DIR"/setup.bash
279286

@@ -732,6 +739,9 @@ function _tue-env
732739
elif [[ ${cmd} == "remove" || ${cmd} == "rm" || ${cmd} == "remove-venv" || ${cmd} == "rm-venv" ]] && [[ "${COMP_CWORD}" -eq 3 ]]
733740
then
734741
mapfile -t COMPREPLY < <(compgen -W "$(echo -e "'--purge '\n${help_options}")" -- "${cur}")
742+
elif [[ ${cmd} == "switch" ]] && [[ "${COMP_CWORD}" -eq 3 ]]
743+
then
744+
mapfile -t COMPREPLY < <(compgen -W "$(echo -e "'--persistent '\n${help_options}")" -- "${cur}")
735745
elif [[ ${cmd} == "init-venv" ]] && [[ "${COMP_CWORD}" -eq 3 ]]
736746
then
737747
mapfile -t COMPREPLY < <(compgen -W "$(echo -e "'--include-system-site-packages='\n${help_options}")" -- "${cur}")

0 commit comments

Comments
 (0)