Requires ngrok and gh-auth:
brew install ngrok
gem install github-auth
#!/usr/bin/env sh | |
usage () { | |
echo "Opens a tunnel to a tmux session for pairing" | |
echo " Usage: pair GITHUB_USERNAME TMUX_SESSION" | |
return 0 | |
} | |
pair () { | |
local session=$1 | |
if [ -z $session ]; then | |
usage | |
return 1 | |
fi | |
sudo systemsetup -setremotelogin on # enable SSH server | |
for user in ${@:2} | |
do | |
gh-auth add --users $user --command="TERM=screen-256color-bce $(which tmux) -2 attach -t $session" | |
done | |
# TODO make temp user alias | |
local ssh_user='pair' | |
ngrok --log stdout --proto=tcp 22 | copy | |
for user in ${@:2} | |
do | |
gh-auth remove --users $user | |
done | |
yes "yes" | sudo systemsetup -setremotelogin off 1> /dev/null # disable SSH server | |
return 0 | |
} | |
copy () { | |
while read ngrok_out | |
do | |
echo "$ngrok_out" | |
echo "$ngrok_out" | grep "Tunnel established at" > /dev/null 2>&1 | |
if [ "$?" -eq "0" ]; then | |
local port=$(echo "$ngrok_out" | sed 's/^.*Tunnel established at tcp:\/\/ngrok.com:\([0-9][0-9]*\)$/\1/') | |
local pair_cmd="ssh -p $port -A [email protected]" | |
echo "$pair_cmd" | pbcopy | |
echo "Pairing tunnel established: $pair_cmd" | |
continue | |
fi | |
done | |
} | |
pair $@ |
#!/usr/bin/env sh | |
usage () { | |
echo "End a pairing session" | |
echo " Usage: unpair GITHUB_USERNAME" | |
} | |
unpair() { | |
local user=$1 | |
if [ -z $user ]; then usage; fi | |
gh-auth remove --users $user | |
echo "yes" | systemsetup -setremotelogin off 1> /dev/null # disable SSH server | |
} | |
unpair $@ |