Reputation: 553
I have the following script:
#!/bin/sh
# Startup tmux session, activate env inside session, wait, execute invoke command
DIR=$(echo $DIR_HOME)
CLOUD=$'cloud_sql'
tmux new -s $CLOUD -d
printf "Starting: $CLOUD \n"
tmux send-keys "cd $DIR_HOME" C-m
tmux send-keys 'pipenv shell' C-m
printf 'Env Started! \n'
if [[ "-z ${ENV_ACTIVE}" ]]; then
tmux send-keys -t $CLOUD "wait 15" C-m
tmux send-keys -t $CLOUD 'inv gce.cloud-sql-proxy -p 5432' C-m
else
tmux send-keys 'Server not ready!'
fi
printf "$CLOUD started. Attach using: \n\n"
printf "tmux attach -t $CLOUD \n\n"
exit 0
I'd like for the pipenv shell
command to finish before (inside the tmux session) running inv gce.cloud-sql-proxy ..
but for some reason I see it executes those commands before/during the activation of pipenv shell
..
On a side note, if I added a tmux attach -t $CLOUD
before the if statement, it seemed to work although this was ideal and id like to exit the tmux session upon completion.
Thanks for your help!
Upvotes: 2
Views: 637
Reputation: 2403
I had the same problem, for me it was:
tmux send-keys "pipenv shell" C-m
tmux send-keys "python run.py" C-m
I solved it by appending the following to my Pipfile:
[scripts]
serve = "python run.py"
Then I changed my tmux to:
tmux send-keys "pipenv run serve" C-m
This runs my script called serve, i.e., runs a program using the env without needing to load it first. You can probably do the same by creating a script in Pipfile for inv gce.cloud-sql.proxy... and run that.
Upvotes: 1