Skip to content

Instantly share code, notes, and snippets.

@akarca
Created January 7, 2025 13:29
Show Gist options
  • Save akarca/1f2a2bc69fcae6def2e66d5c29658774 to your computer and use it in GitHub Desktop.
Save akarca/1f2a2bc69fcae6def2e66d5c29658774 to your computer and use it in GitHub Desktop.
pip install and add package name and version to requirements.txt
#!/usr/bin/env bash
if [ -z "$1" ]
then
echo "No argument supplied. Usage: add-requirement Django"
fi
FILE="requirements.txt"
if [ -f $FILE ]; then
echo "Add requirement $1 to $FILE"
else
echo "File $FILE does not exist."
exit 1
fi
pip install $1
RESULT=$(pip freeze | grep $1)
echo $RESULT
if [[ $RESULT == $1==* ]]
then
RESULT2=$(cat $FILE | grep $1)
if [[ $RESULT2 == $1==* ]]
then
echo "Already added $1 to $FILE"
else
echo $RESULT >> $FILE
echo "Added $RESULT to $FILE"
fi
else
echo "Can't add $1 to $FILE. pip package name is not equals to $1";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment