aboutsummaryrefslogtreecommitdiff
path: root/with_env
blob: c94e8b9a33c54a3922e58cb9ef5b629bf1aafadb (plain) (blame)
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
#!/bin/bash
set +x
environ=base
commands=()

while [[ $# > 0 ]]
do
    key="$1"
    case $key in
        -n|--name)
            environ="$2"
            shift 2
            ;;
        *)
            commands+=("$1")
            shift
            ;;
    esac
done


type conda &>/dev/null
if [[ $? != 0 ]]; then
    venv_root=${HOME}/.venvs
    venv_path=${venv_root}/${environ}

    [[ ! -d ${venv_root} ]] && mkdir -p ${venv_root}
    [[ ! -d ${venv_path} ]] && python -m venv "${venv_path}"

    source "${venv_path}/bin/activate"
else
    source activate ${environ}
fi

"${commands[@]}"
exit $?