Last active
July 28, 2025 12:06
-
-
Save 3nws/1294853f45845f3642964b47bc411cac to your computer and use it in GitHub Desktop.
Simple bash script that creates a shortlink using [bit](https://github.com/sjdonado/bit).
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
| #!/usr/bin/bash | |
| set -euo pipefail | |
| host=$1 | |
| apiKey=$2 | |
| url=$3 | |
| # alternatively | |
| # echo Enter URL to shorten: && read url | |
| response=$(curl --silent --location "https://${host}/api/links" \ | |
| --header "X-Api-Key: ${apiKey}" \ | |
| --header "Content-Type: application/json" \ | |
| --data "{\"url\": \"https://${url}\"}") | |
| refer=$(echo "$response" | jq -r '.data.refer') | |
| new_refer=$(echo "$refer" | sed -E "s|https?://[^/]+|https://${host}|") | |
| echo "$new_refer" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment