Skip to content

Instantly share code, notes, and snippets.

@osamaqarem
Last active June 19, 2024 04:43
Show Gist options
  • Save osamaqarem/ae0707d31e9dc0f66acd927a003513f9 to your computer and use it in GitHub Desktop.
Save osamaqarem/ae0707d31e9dc0f66acd927a003513f9 to your computer and use it in GitHub Desktop.
fish functions: start ngrok and copy url to clipboard
function ng --description "ng <port>"
if test -z "$argv[1]"
set port 3000
else
set port $argv[1]
end
# Run ngrok in the background
ngrok http $port > /dev/null &
# Allow ngrok to establish the tunnel
sleep 1
# Extract the forwarding URL from ngrok's console output
set forwarding_url (curl -s http://127.0.0.1:4040/api/tunnels | awk -F'public_url":"' '{print $2}' | awk -F'"' '{print $1}')
# Trim whitespace, newlines and copy the forwarding URL to clipboard
echo $forwarding_url | tr -d '\n' | pbcopy
# Display a message with the copied URL
echo "Forwarding URL ($port): $forwarding_url copied to clipboard."
end
function ngk
# Get the PID of the ngrok process
set ngrok_pid (pgrep ngrok)
if test -n "$ngrok_pid"
# Terminate the ngrok process
kill $ngrok_pid
echo "ngrok connection terminated."
else
echo "ngrok process not found."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment