aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaximilian Stauss <max.stauss@gmail.com>2019-07-07 14:44:55 +0200
committerGitHub <noreply@github.com>2019-07-07 14:44:55 +0200
commite8344852666afb1c518db56f9009d54fd2331a49 (patch)
tree98ee1e91fde5a1b30fa5344ac3ff222010928b26
parent8417d06bbefd25edfe58bed5e28a5fd441794fe5 (diff)
make it run under zsh
changed `if [ ... ];` to `if [[ ... ]];` because `if [ "$1" == "." ];` does not work in zsh see: https://unix.stackexchange.com/questions/255480/why-does-behave-differently-inside-in-zsh-and-bash
-rwxr-xr-xvenvworkon.sh22
1 files changed, 11 insertions, 11 deletions
diff --git a/venvworkon.sh b/venvworkon.sh
index 07fcaf4..957c00f 100755
--- a/venvworkon.sh
+++ b/venvworkon.sh
@@ -1,17 +1,17 @@
workon() {
# Sets WORKON_HOME to default if not set already
- if [ -z $WORKON_HOME ]; then
+ if [[ -z $WORKON_HOME ]]; then
WORKON_HOME="$HOME/.venv"
fi
# Creates WORKON_HOME directory if not exists
- if [ ! -e $WORKON_HOME ]; then
+ if [[ ! -e $WORKON_HOME ]]; then
mkdir -p $WORKON_HOME
echo "Virtual env directory created in $WORKON_HOME"
fi
# Quit if there is no arguments, while showing available venvs
- if [ "$#" -lt "1" ]; then
+ if [[ "$#" -lt "1" ]]; then
echo "Usage: workon ENV_NAME PYTHON_VERSION"
echo "Available envs:"
ls "$WORKON_HOME"
@@ -22,23 +22,23 @@ workon() {
python_version="3"
projectdir=""
- if [ "$1" == "." ]; then
+ if [[ "$1" == "." ]]; then
target=$(basename `pwd`)
envdir="$WORKON_HOME/$target"
projectdir=$(pwd)
fi
- if [ "$#" -gt "1" ]; then
+ if [[ "$#" -gt "1" ]]; then
python_version=$2
fi
python_exec="python$python_version"
# Creates virtual env if doesn't exists
- if [ ! -e "$envdir" ]; then
+ if [[ ! -e "$envdir" ]]; then
$python_exec -m venv $envdir
- if [ "$projectdir" != "" ]; then
+ if [[ "$projectdir" != "" ]]; then
echo "projectdir=$projectdir" > "$envdir/postactivate.sh"
fi
@@ -49,20 +49,20 @@ workon() {
unset envdir # VIRTUAL_ENV is now set by bin/activate
# Source postactivate.sh if exists in the virtual env
- if [ -e "$VIRTUAL_ENV/postactivate.sh" ]; then
+ if [[ -e "$VIRTUAL_ENV/postactivate.sh" ]]; then
source "$VIRTUAL_ENV/postactivate.sh"
fi
- if [ -e "$projectdir/.env" ]; then
+ if [[ -e "$projectdir/.env" ]]; then
. "$projectdir/.env"
fi
# Jumps to project directory if exists and PROJECT_HOME is set
projecthome="$PROJECT_HOME/$(basename $VIRTUAL_ENV)"
- if [ -d "$projecthome" ]; then
+ if [[ -d "$projecthome" ]]; then
cd "$projecthome"
- if [ -e "$projecthome/.env" ]; then
+ if [[ -e "$projecthome/.env" ]]; then
. "$projecthome/.env"
fi
fi