Skip to content

Instantly share code, notes, and snippets.

@akarca
Created January 7, 2025 13:29

Revisions

  1. akarca created this gist Jan 7, 2025.
    34 changes: 34 additions & 0 deletions add-requirement
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    #!/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