-
-
Save karampok/64067862052b2565b348812f0cb13bfc to your computer and use it in GitHub Desktop.
pair with tmux/ngrok
This file contains 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/sh | |
# http://iamvery.com/2013/11/16/tmux-pairing-anywhere-on-your-box.html | |
command="$(basename "$0")" | |
# Make sure dependencies are installed | |
[ ! "$(command -v gh-auth)" ] && echo "gh-auth not found (gem install github-auth)" && exit 1 | |
[ ! "$(command -v tmux)" ] && echo "tmux not found" && exit 1 | |
help(){ | |
echo "Usage: "$command" <subcommand> [options]\n" | |
echo "Subcommands:" | |
echo " add Add a github user" | |
echo " rm Remove a github user" | |
echo " ls List github users" | |
echo " up Open shared tmux session" | |
echo " ssh Start a reverse tunnel for pair sharing" | |
echo " See: https://ngrok.com" | |
} | |
add(){ | |
gh-auth add --users "$@" --command="$(which tmux) attach -t pairing" | |
} | |
rm(){ | |
gh-auth remove --users "$@" | |
} | |
ls(){ | |
gh-auth list | |
} | |
up(){ | |
for user in "$@";do | |
add "$user" | |
done | |
tmux rename-session pairing | |
tmux send-keys "ngrok tcp -region eu 22" C-m | |
tmux split-window | |
sleep 2 # some delay so tunnel has time to get up | |
tmux send-keys "pair ssh" C-m | |
} | |
ssh(){ | |
host="0.tcp.eu.ngrok.io" | |
port=$(curl -s http://localhost:4040/api/tunnels|jq -r '.tunnels[0].public_url'| cut -d : -f3) | |
user=tmux | |
ssh_command="ssh -p $port $user@$host" | |
echo "$ssh_command" | |
echo "$ssh_command" | pbcopy | |
} | |
subcommand=$1 | |
case $subcommand in | |
'' | '-h' | '--help') | |
help ;; | |
*) | |
shift | |
${subcommand} $@ | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment