Skip to content

Instantly share code, notes, and snippets.

@0xOsprey
Created May 12, 2024 22:30
Show Gist options
  • Save 0xOsprey/0e9bd8a34d03daf9f0c3025e6c853109 to your computer and use it in GitHub Desktop.
Save 0xOsprey/0e9bd8a34d03daf9f0c3025e6c853109 to your computer and use it in GitHub Desktop.
Raycast script for shortening a URL in clipboard
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Shorten URL From Clipboard
# @raycast.mode silent
# @raycast.packageName Browsing
# Optional parameters:
# @raycast.icon 🔗
# Documentation:
# @raycast.author Thomas Paul Mann
# @raycast.authorURL https://github.com/thomaspaulmann
# @raycast.description Shorten the URL in your Clipboard with Tiny URL.
regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
pasteboardString=$(pbpaste)
if [[ $pasteboardString =~ $regex ]]
then
result=$(curl "https://tinyurl.com/api-create.php?url=$pasteboardString")
if [[ $result != "Error" ]]
then
echo $result | pbcopy
echo "Copied shorten URL"
else
echo "URL cannot be shorten"
exit 1
fi
else
echo "String in clipboard is a not valid URL"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment