From 598d455e6b3309b24a8e75d902c71b56cf160d77 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 8 Aug 2025 09:38:18 +0200 Subject: [PATCH] Activated python venv for zsh und bash --- Makefile | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 2f4c1e3..201297f 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: install setup +.PHONY: install setup uninstall setup: install @python main.py install @@ -7,21 +7,25 @@ install: @echo "Making 'main.py' executable..." @chmod +x main.py @echo "Checking if global user virtual environment exists..." + @mkdir -p ~/.venvs/pkgmgr @test -d ~/.venvs/pkgmgr || (echo "Creating global venv at ~/.venvs/pkgmgr..." && python -m venv ~/.venvs/pkgmgr) @echo "Installing required Python packages into ~/.venvs/pkgmgr..." @~/.venvs/pkgmgr/bin/pip install --upgrade pip @~/.venvs/pkgmgr/bin/pip install -r requirements.txt - @echo "Ensuring ~/.bashrc exists..." - @test -f ~/.bashrc || touch ~/.bashrc + @echo "Ensuring ~/.bashrc and ~/.zshrc exist..." + @touch ~/.bashrc ~/.zshrc @echo "Ensuring automatic activation of ~/.venvs/pkgmgr for this user..." - @grep -qxF 'if [ -d "$$HOME/.venvs/pkgmgr" ]; then . "$$HOME/.venvs/pkgmgr/bin/activate"; echo "Global Python virtual environment '\''~/.venvs/pkgmgr'\'' activated."; fi' ~/.bashrc \ - || echo 'if [ -d "$$HOME/.venvs/pkgmgr" ]; then . "$$HOME/.venvs/pkgmgr/bin/activate"; echo "Global Python virtual environment '\''~/.venvs/pkgmgr'\'' activated."; fi' >> ~/.bashrc - @echo "Installation complete. Please restart your shell (or 'exec bash') for the changes to take effect." + @for rc in ~/.bashrc ~/.zshrc; do \ + rc_line='if [ -d "$${HOME}/.venvs/pkgmgr" ]; then . "$${HOME}/.venvs/pkgmgr/bin/activate"; echo "Global Python virtual environment '\''~/.venvs/pkgmgr'\'' activated."; fi'; \ + grep -qxF "$${rc_line}" $$rc || echo "$${rc_line}" >> $$rc; \ + done + @echo "Installation complete. Please restart your shell (or 'exec bash' or 'exec zsh') for the changes to take effect." uninstall: @echo "Removing global user virtual environment if it exists..." @rm -rf ~/.venvs/pkgmgr - @echo "Cleaning up ~/.bashrc entries..." - @sed -i '/if \[ -d "\$\$HOME\/\.venvs\/pkgmgr" \]; then \. "\$\$HOME\/\.venvs\/pkgmgr\/bin\/activate"; echo "Global Python virtual environment '\\''~\/.venvs\/pkgmgr'\\'' activated."; fi/d' ~/.bashrc - @echo "Uninstallation complete. Please restart your shell (or 'exec bash') for the changes to fully apply." - + @echo "Cleaning up ~/.bashrc and ~/.zshrc entries..." + @for rc in ~/.bashrc ~/.zshrc; do \ + sed -i '/\.venvs\/pkgmgr\/bin\/activate"; echo "Global Python virtual environment '\''~\/\.venvs\/pkgmgr'\'' activated."; fi/d' $$rc; \ + done + @echo "Uninstallation complete. Please restart your shell (or 'exec bash' or 'exec zsh') for the changes to fully apply."