aboutsummaryrefslogtreecommitdiff
path: root/lib/spawn
blob: 1b30c1976e300e9bce48d24cdd67a58936f9faa5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh
. ./vars

SOCKDIR=$(mktemp -d)
SOCKF=${SOCKDIR}/usock

trap 'rm -rf $SOCKDIR' EXIT INT

# Start tmux, if needed
if ! tmux ls | grep -q "$tmux_session"; then
	tmux new -s "$tmux_session" -d
fi
# Create window

tmux new-window -t "$tmux_session" \
	"stty raw -echo ; socat file:\$(tty),raw,echo=0 UNIX-LISTEN:${SOCKF},umask=0077"

# Wait for socket
while test ! -e "${SOCKF}" ; do sleep 1 ; done

# Use socat to ship data between the unix socket and STDIO.
exec socat STDIO "UNIX-CONNECT:${SOCKF}"