Skip to content

Instantly share code, notes, and snippets.

@zacstewart
Last active October 21, 2019 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zacstewart/50c1689d54d0e834093ab9a65d300586 to your computer and use it in GitHub Desktop.
Save zacstewart/50c1689d54d0e834093ab9a65d300586 to your computer and use it in GitHub Desktop.
Pair with all your friends on GitHub :DDDDD

pair

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 $ssh_user@ngrok.com"
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 $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment