Last active
February 2, 2019 13:51
-
-
Save michaelbrooks/9553013 to your computer and use it in GitHub Desktop.
.bashrc to enable virtualenvwrapper for MinGW bash shells
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If you are using a MinGW environment | |
# such as that provided by the bash shell included | |
# with GitHub for Windows, this script will | |
# make sure you have the necessary tools installed | |
# to run virtualenvwrapper. | |
# | |
# You can add the following to your .bashrc file to automatically | |
# download and run this gist when you start your shell: | |
# | |
# if [ ! -e $HOME/.bash_virtualenvwrapper.sh ]; then | |
# curl -L https://gist.github.com/michaelbrooks/9553013/raw -o $HOME/.bash_virtualenvwrapper.sh | |
# fi | |
# | |
# if [ -e $HOME/.bash_virtualenvwrapper.sh ]; then | |
# source $HOME/.bash_virtualenvwrapper.sh | |
# fi | |
if [ "$MSYSTEM" ]; then | |
# Find your python | |
PYTHON_DIR=$(dirname `which python`) | |
# See http://www.asyndetic.com/blog/2012/05/01/virtualenvwrapper-is-for-windows-users-too/ | |
if [ -e "$PYTHON_DIR/Scripts/virtualenvwrapper.sh" ]; then | |
echo "Setting up virtualenvwrapper..." | |
# mktemp is required by virtualenvwrapper, but is not necessarily | |
# included in your MinGW setup. | |
if ! command -v mktemp > /dev/null; then | |
echo "Installing mktemp..." | |
objname=/tmp/mktemp-1.6-2-msys-1.0.13-bin | |
curl -L -o $objname.tar.lzma http://downloads.sourceforge.net/project/mingw/MSYS/Extension/mktemp/mktemp-1.6-2/mktemp-1.6-2-msys-1.0.13-bin.tar.lzma > /dev/null | |
if (command -v 7za > /dev/null); then | |
7za x $objname.tar.lzma -o/tmp > /dev/null | |
7za x $objname.tar -o/ > /dev/null | |
rm $objname.tar $objname.tar.lzma > /dev/null | |
elif (command -v tar > /dev/null) && (command -v lzma > /dev/null); then | |
tar --lzma -xf $objname.tar.lzma --directory=/ | |
rm $objname.tar.lzma | |
else | |
echo "ERROR: Installing mktemp requires 7za or lzma." | |
fi | |
fi | |
if ! command -v fmt > /dev/null; then | |
echo "Making a fake fmt command..." | |
cat > /bin/fmt << EOF | |
#!/bin/bash | |
while read x; do | |
echo \$x | sed "s;\s\+;\n;g" | |
done | |
EOF | |
fi | |
if ! command -v mktemp > /dev/null; then | |
echo "ERROR: unable to install mktemp.exe! Cannot set up virtualenvwrapper." | |
else | |
export WORKON_HOME=$HOME/.virtualenvs | |
# This is the case with the GitHub bash shell | |
export MSYS_HOME=/ | |
source $PYTHON_DIR/Scripts/virtualenvwrapper.sh | |
echo "...done." | |
fi | |
else | |
echo "Error: virtualenvwrapper not installed. Use 'pip install virtualenvwrapper' to install it globally." | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you are using a MinGW environment such as that provided by the bash shell included with GitHub for Windows, this script will make sure you have the necessary tools installed to run virtualenvwrapper.
You can add the following to your .bashrc file to automatically download and run this gist when you start your shell: