Skip to content

Instantly share code, notes, and snippets.

@dpryden
Created April 3, 2018 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpryden/92a9a94ed21207bba549bbe7ac41ca9f to your computer and use it in GitHub Desktop.
Save dpryden/92a9a94ed21207bba549bbe7ac41ca9f to your computer and use it in GitHub Desktop.
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