Skip to content

Instantly share code, notes, and snippets.

@colemilne54
Forked from mlsteele/ngrok-copy
Last active August 9, 2023 02:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colemilne54/a2f4b3c6cd894ecd0dd0bf95b673aabb to your computer and use it in GitHub Desktop.
Save colemilne54/a2f4b3c6cd894ecd0dd0bf95b673aabb to your computer and use it in GitHub Desktop.
Copy the url of the active ngrok connection to the clipboard.
#!/usr/bin/env bash
# Copy the url of the active ngrok connection to the clipboard.
# Usage:
# ngrok-copy # copies e.g. https://3cd67858.ngrok.io to clipboard.
# ngrok-copy -u # copies e.g. http://3cd67858.ngrok.io to clipboard.
if [[ "$1" == "-u" ]]; then
NGROK_URL=`curl -s http://127.0.0.1:4043/api/tunnels | grep "https://.*.ngrok-free.app" -oh`
else
NGROK_URL=`curl -s http://127.0.0.1:4043/api/tunnels | grep "https://.*.ngrok-free.app" -oh`
fi
if [[ $NGROK_URL != *"http"* ]]; then
echo "No url found. Is ngrok running?"
exit 1
fi
if [ "$(uname)" == "Darwin" ]; then
# OSX
echo $NGROK_URL | pbcopy
else
# Linux
echo $NGROK_URL | xclip -selection clipboard
fi
echo "Copied to clipboard: $NGROK_URL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment