Skip to content

Instantly share code, notes, and snippets.

@paxperscientiam
Last active December 28, 2017 23:23
Show Gist options
  • Save paxperscientiam/3f8370084fe28e110b740bd9b95389b2 to your computer and use it in GitHub Desktop.
Save paxperscientiam/3f8370084fe28e110b740bd9b95389b2 to your computer and use it in GitHub Desktop.
Custom shell functions for invoking pip3 with python36 and pip with python27 for installation and packages listing
#!/usr/bin/env bash
# Note: only tested on macOS; asssumes appropriate pips installed
# Disclaimer: use at your own peril
# Parting words: have a nice day
shopt -s expand_aliases
# edit this accordingly
pyverz=(
"2.7"
"3.4"
"3.6"
)
for py in "${pyverz[@]}"
do
command -v "python${py}" > /dev/null
if [[ $? -eq 0 ]]; then
pyvar="python${py} -m pip --isolated"
alias py="${pyvar}"
source <(cat << EOF
function gpip${py//./} ()
{
if [[ "\$*" =~ "list" ]]
then
py "\$@" --format=columns
elif [[ "\$*" =~ "install" ]]
then
sudo -H ${pyvar} "\$@"
elif [[ "\$*" =~ "upgrade" ]]
then
py freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 sudo -H ${pyvar} install -U
else
echo "Unsupported option."
fi
}
EOF
)
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment