Skip to content

Instantly share code, notes, and snippets.

@varenc
Forked from mlsteele/ngrok-copy
Last active June 25, 2023 14:56
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save varenc/6addfa03b03b318fe32612f67027bb1c to your computer and use it in GitHub Desktop.
Save varenc/6addfa03b03b318fe32612f67027bb1c to your computer and use it in GitHub Desktop.
Copy the url of the active ngrok connection to the clipboard. Updated Oct-2019
#!/usr/bin/env bash
# Copy the url of the active ngrok connection to the clipboard. Updated for latest ngrok (Oct 2019)
#
# Usage:
# ngrok-copy # copies e.g. https://3cd67858.ngrok.io to clipboard.
# ngrok-copy -u # copies e.g. http://3cd67858.ngrok.io to clipboard.
#
# Modified from the original script at https://gist.github.com/mlsteele/f57adc1fab5c44656d6d
if [[ "$1" == "-u" ]]; then
NGROK_URL=`curl -s http://127.0.0.1:4040/api/tunnels | grep "http://\w*.ngrok.io" -oh`
else
NGROK_URL=`curl -s http://127.0.0.1:4040/api/tunnels | grep "https://\w*.ngrok.io" -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"
@Revanth-Kausikan
Copy link

Thanks! This works just as expected.

@adimuhamad
Copy link

adimuhamad commented Jun 25, 2023

How do i use it on windows?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment