I'm looking for a way to wait execution then detach from current tmux session through bash command line.
For example currently I'm trying to build a deployment automation command line tool. It should does:
- create a new tmux session, attache to it,
- run a file (e.g. build) showing user its stdout,
- when its execution ends detach from the session,
- and capture-pane to if the stdout is finished in a success way or an error way then if it's success is true continues to the next file (e.g. launch) and showing user its stdout creating and attaching to a new tmux session, and so on.
I tried the followings, however it didn't work as it doesn't wait for the previous commands but immediately detaches. (Note: assume the build.sh takes tens of seconds to execute with its stdout)
tmux a -t tmp \; \
set-buffer ". /root/pg/myapp/production/.deploy/remote/build.sh;" \; paste-buffer \; send-keys C-m \; \
set-buffer "tmux wait-for -S done;" \; paste-buffer \; send-keys C-m \; \
set-buffer "tmux wait-for done;" \; paste-buffer \; send-keys C-m \; \
detach \;
tmux a -t tmp \; \
set-buffer ". /root/pg/myapp/production/.deploy/remote/build.sh;" \; paste-buffer \; send-keys C-m \; \
send-keys C-b \; \
send-keys d \;
versions:
# tmux -V
tmux 3.0a
# bash --version
GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
Thanks.