Skip to content

Instantly share code, notes, and snippets.

@wosc
Created January 12, 2019 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wosc/680f87845d0fd9d8b4a9e2f8c42f98a2 to your computer and use it in GitHub Desktop.
Save wosc/680f87845d0fd9d8b4a9e2f8c42f98a2 to your computer and use it in GitHub Desktop.
Launch a command in a new macOS terminal window and block until it exits
#!/bin/bash
# Adapted from https://github.com/jlebon/files/blob/master/bin/gnome-terminal-wrapper
set -euo pipefail
# Needs `flock` command from https://github.com/discoteq/flock
# which can be installed via homebrew (which is not on the PATH by default)
export PATH=/usr/local/bin:$PATH
tmpf=$(mktemp)
trap "rm -f $tmpf" EXIT
session=$(tmux new -d -P flock $tmpf "$@")
osascript -e "tell application \"Terminal\"" -e "do script \"tmux attach -t $session\"" -e "activate" -e "end tell"
flock $tmpf true
osascript -e 'tell application "Terminal"' -e 'do script "exit" in tab 1 of front window' -e 'end tell'
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment