Last active
June 19, 2024 04:43
-
-
Save osamaqarem/ae0707d31e9dc0f66acd927a003513f9 to your computer and use it in GitHub Desktop.
fish functions: start ngrok and copy url to clipboard
This file contains hidden or 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
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 |
This file contains hidden or 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
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