Skip to content

Instantly share code, notes, and snippets.

@hashworks
Created November 6, 2020 17:25
Show Gist options
  • Save hashworks/6d6e4eae8984a5018f7692a796d570b4 to your computer and use it in GitHub Desktop.
Save hashworks/6d6e4eae8984a5018f7692a796d570b4 to your computer and use it in GitHub Desktop.
BASH function for kutt.it URL shortener services
KUTT_HOST="https://kutt.it"
KUTT_API_KEY="API_KEY"
kutt() {
if [[ "$1" == "delete" ]] && [[ -n "$2" ]]; then
curl -s -H "X-API-KEY: $KUTT_API_KEY" \
-X DELETE \
"$KUTT_HOST/api/v2/links/$2" | jq
elif [[ -z "$1" ]]; then
curl -s -H "X-API-KEY: $KUTT_API_KEY" \
"$KUTT_HOST/api/v2/links" | jq
elif [[ "$1" != "help" ]] && [[ "$1" != "--help" ]]; then
curl -s -H "X-API-KEY: $KUTT_API_KEY" \
-H "Content-Type: application/json" \
--data "{
\"target\": \"$1\",
\"password\": \"$2\",
\"expire_in\": \"$3\",
\"description\": \"$4\"
}" \
"$KUTT_HOST/api/v2/links" | jq
else
echo "kutt"
echo "kutt help"
echo "kutt <target-url> [<password> <expire_in> <description>]"
echo "kutt delete <uuid>"
return 2
fi
}
@hashworks
Copy link
Author

kutt "https://github.com"

{
  "id": "accefebc-f139-4f08-8b6a-e45b89ce0873",
  "address": "NFJ",
  "description": null,
  "banned": false,
  "password": false,
  "expire_in": null,
  "target": "https://github.com",
  "visit_count": 0,
  "created_at": "2020-11-06T17:26:22.533Z",
  "updated_at": "2020-11-06T17:26:22.533Z",
  "link": "https://kutt.it/NFJ"
}

kutt

{
  "total": 1,
  "limit": 10,
  "skip": 0,
  "data": [
    {
      "id": "accefebc-f139-4f08-8b6a-e45b89ce0873",
      "address": "NFJ",
      "banned": false,
      "created_at": "2020-11-06T17:26:22.533Z",
      "updated_at": "2020-11-06T17:26:22.533Z",
      "password": false,
      "description": null,
      "expire_in": null,
      "target": "https://github.com",
      "visit_count": 0,
      "domain": null,
      "link": "https://kutt.it/NFJ"
    }
  ]
}

kutt delete accefebc-f139-4f08-8b6a-e45b89ce0873

{
  "message": "Link has been deleted successfully."
}
$ kutt "https://gist.github.com" | jq -r '.link'`
https://kutt.it/7zw

@fabianski7
Copy link

curl -s -H "X-API-KEY: $KUTT_API_KEY" \
			-H "Content-Type: application/json" \
			--data "{
				\"target\": \"$1\",
				\"password\": \"$2\",
				\"expire_in\": \"$3\",
				\"description\": \"$4\",
				\"domain\": \"your-custom-domain.tld\"
			}"

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