I have the following workflow which I would like to automate (for Unix):
cd repos/data-warehouse
poetry shell
do my stuff
exit (to deactivate the poetry shell)
cd ..
cd etl
poetry shell
For that, I've created the following shell script, which I have into a .sh
file:
#!/bin/bash
REPO_NAME="$1"
TARGET_DIR=~/repos/$REPO_NAME
if [ -n "$VIRTUAL_ENV" ]; then
exit
fi
cd $TARGET_DIR
poetry shell
So that every time I run an alias (i.e fdev), i would just execute fdev data-warehouse and it would execute all the necessary commands to be in that folder with the poetry shell activated.
To make the alias, i've added this line to my nano ~/.zshrc
file:
alias fdev="source ~/repos/fdev.sh"
According to some links, like call "exit" from within shell script, Exit shell script from python and https://superuser.com/questions/1547228/how-to-activate-python-virtualenv-through-shell-script, using the source should work because the exit
command will be executed within the same shell.
However, if I already have a poetry shell activated and I run the command from the terminal (i.e fdev etl
, it just exits the poetry shell and the shell script stops, and I have to execute the command again to make it effectively change the directory and activate the new poetry shell.
Is there any way of accomplishing what I want to do? Thanks