Skip to content

Instantly share code, notes, and snippets.

@harikt
Forked from miraculixx/.bashrc
Created July 26, 2016 07:12
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 harikt/3dc9a6c61be2d58b7a5c7e5984298b62 to your computer and use it in GitHub Desktop.
Save harikt/3dc9a6c61be2d58b7a5c7e5984298b62 to your computer and use it in GitHub Desktop.
add and remove pip install/uninstall from requirements.txt automatically
# add pip install/uninstall to requirements.txt automatically
pipr() {
if [ "$1" == "install" ]; then
pip $1 $2
pip freeze | grep -i $2 >> requirements.txt
echo ok, added $2 as:
tail -n1 requirements.txt
fi
if [ "$1" == "uninstall" ]; then
echo y | pip $1 $2 >> .pipremoved
grep -i "successfully uninstalled" .pipremoved | grep -o -i $2 >> requirements.removed
cp requirements.txt requirements.bak
tail -n1 requirements.removed | xargs -I{} grep -v {} requirements.bak > requirements.txt
echo ok, removed:
tail -n1 requirements.removed
rm .pipremoved >/dev/nul
fi
}
@harikt
Copy link
Author

harikt commented Jul 26, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment