Created
January 12, 2019 13:59
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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