Skip to content

Instantly share code, notes, and snippets.

@awreece
Last active December 19, 2015 15:38
Show Gist options
  • Save awreece/5977532 to your computer and use it in GitHub Desktop.
Save awreece/5977532 to your computer and use it in GitHub Desktop.
#!/bin/zsh
zmodload zsh/net/tcp
if [[ $# -ne 2 ]] || [[ $1 == '-l' ]]; then
echo "$0 <host> <port>:" >&2
echo " Sends stdin to <host>:<port>" >&2
exit 1
fi
ztcp $1 $2
fd=$REPLY
if [[ -z $fd ]]; then
exit 2
fi
cat <&$fd &
CAT_PID=$!
trap "kill $CAT_PID" SIGINT
trap "kill $$" SIGCHLD
# There is a bit of a race here, but YOLO.
cat >&$fd
ztcp -c $fd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment