diff --git a/venvsetup.sh b/venvsetup.sh index 3bbe444..331122f 100755 --- a/venvsetup.sh +++ b/venvsetup.sh @@ -20,7 +20,7 @@ fi create_venv() { if [ -z "$venv_path" ]; then echo "No virtual environment found." - read -p "Type the name of your venv: " name < /dev/tty + read -p "Type the name of your venv: " name echo "Creating virtual environment: $name" python3 -m venv "$name" venv_path="./$name" @@ -30,12 +30,14 @@ create_venv() { # --- Add venv to .gitignore gitignore() { - if [ -f .gitignore ] && grep -qx "$venv_path" .gitignore; then - return + if [ -f .gitignore ]; then + if grep -qx "$venv_path" .gitignore; then + return + fi fi echo "Do you want to add the venv to .gitignore? (recommended)" - read -p " y / n " choice < /dev/tty + read -p " y / n " choice if [ "$choice" = "y" ]; then echo "$venv_path" >> .gitignore echo "Added $venv_path to .gitignore" @@ -59,7 +61,7 @@ activate_venv() { requirements() { if [ -n "$existing_req" ]; then echo "requirements.txt detected. Install dependencies?" - read -p " y / n " choice < /dev/tty + read -p " y / n " choice if [ "$choice" = "y" ]; then pip install -r "$existing_req" echo "Dependencies installed" @@ -67,15 +69,14 @@ requirements() { fi } -# --- Install one package +# --- Install packages interactively installer() { - read -p "Type the package you need to install: " package < /dev/tty + read -p "Type the package you need to install: " package pip install "$package" } -# --- Alfred logic (first question + follow-ups) alfred() { - read -p "Do you want to install a package? (y / n) " choice < /dev/tty + read -p "Do you want to install a package? (y / n) " choice if [ "$choice" != "y" ]; then return fi @@ -83,7 +84,7 @@ alfred() { installer while true; do - read -p "Do you want to install another package? (y / n) " choice < /dev/tty + read -p "Do you want to install another package? (y / n) " choice if [ "$choice" = "y" ]; then installer else @@ -92,6 +93,7 @@ alfred() { done } + # ------------------ MAIN ------------------ create_venv @@ -104,3 +106,4 @@ echo "" echo "Your venv is ready!" echo "To activate it later, run:" echo "source \"$venv_path/bin/activate\"" +