Created
March 17, 2012 11:36
-
-
Save ichernev/2057859 to your computer and use it in GitHub Desktop.
Switch python versions (2 <-> 3)
This file contains hidden or 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
| #!/bin/bash | |
| # source this file in your ~/.bashrc or ~/.zshrc and then use pyswitch function | |
| _add_shortcut() { | |
| mkdir -p /tmp/bin | |
| cd /tmp/bin | |
| rm -f python | |
| ln -s /usr/bin/python2 python | |
| export PATH="/tmp/bin:$PATH" | |
| echo "using version $(python --version 2>&1 | cut -c8-)" | |
| } | |
| _remove_shortcut() { | |
| export PATH=$(echo "${PATH}:" | sed -e 's_/tmp/bin:__' -e 's_:$__') | |
| rm -rf /tmp/bin | |
| echo "using version $(python --version 2>&1 | cut -c8-)" | |
| } | |
| pyswitch() { | |
| current=$(python --version 2>&1 | cut -c8) | |
| if [ "$current" -eq 2 ]; then | |
| _remove_shortcut | |
| else | |
| _add_shortcut | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment