For anyone landing on the question, and in the absence of a better answer... what I've gone with in the end is installing daemonize
(homepage, homebrew) which does exactly what I want - detach a process from a VSCode-derived terminal such that it survives the terminal being closed. The emulator
line, above, now looks like:
daemonize "$( which emulator )" -avd Pixel_7_Pro_API_34 -no-boot-anim
(daemonize
didn't seem to use the PATH
so I resolve the emulator
executable for it).
It's also possible to remove the if pgrep -x "qemu-system-aarch64" >/dev/null; then...
condition by using the -l
lockfile option but to achieve the logging I have in place I'd have to implement error handling so left it as-is for now.
I'd still be interested in how to do this directly in zsh
without relying on a separate third-party tool, however well it works.