Skip to content

Instantly share code, notes, and snippets.

@dpryden
Created Apr 3, 2018
Embed
What would you like to do?
toxin: Script for running python or shell commands inside a .tox environment
#!/bin/bash
# Run a command inside a Tox environment
if ! [[ -d .tox ]]; then
echo 'Cannot find .tox in this directory!'
exit 1
fi
if [[ "$1" == '-e' ]]; then
toxenv="$2"
shift 2
else
toxenv="$(cd .tox && echo py* | awk '{print $NF}')"
fi
toxdir="$(cd .tox && pwd)"
bindir="$toxdir/$toxenv/bin"
activate_script="$bindir/activate"
if ! [[ -f $activate_script ]]; then
printf 'Cannot find tox env "%s" in current directory!\n' "$toxenv"
exit 1
fi
if [[ "$1" == "" ]]; then
PATH="$bindir:$PATH" /bin/bash --rcfile "$activate_script"
else
PATH="$bindir:$PATH" /bin/bash --rcfile "$activate_script" -c "$*"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment