Skip to content

Instantly share code, notes, and snippets.

@crstauf
Created October 29, 2020 21:08
Show Gist options
  • Save crstauf/6900e0df23726dbf4c370fe59fb8755b to your computer and use it in GitHub Desktop.
Save crstauf/6900e0df23726dbf4c370fe59fb8755b to your computer and use it in GitHub Desktop.
Raycast Script Commands
#!/bin/bash
##################################################################
## Set GitHub username and personal access token and uncomment. ##
##################################################################
# GitHub username
# user=
# GitHub personal access token
# access_key=
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Create GitHub Gist from clipboard
# @raycast.mode compact
# Optional parameters:
# @raycast.packageName GitHub
# @raycast.needsConfirmation true
if [ -z ${user+x} ]; then
echo "GitHub username is missing.";
exit 1;
fi
if [ -z ${access_key+x} ]; then
echo "GitHub personal access token is missing.";
exit 1;
fi
if ! command -v jq &> /dev/null; then
echo "jq is required (https://stedolan.github.io/jq/).";
exit 1;
fi
clipboard=$(pbpaste)
gist_content="$( jq -nc --arg str "$clipboard" '{ "public": false, "files": { "gistfile1.txt": { "content": $str } } }' )"
auth=$(echo -n "$user:$access_key" | base64)
response=$( curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Basic $auth" https://api.github.com/gists -d "$gist_content" )
echo "$response" | jq -r '.html_url' | pbcopy
echo "Created gist and copied URL"
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Save URL to Wayback Machine from clipboard
# @raycast.mode compact
# @raycast.packageName Wayback Machine
# Optional parameters:
url=$(pbpaste)
regex='(https?)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
if [[ $url =~ $regex ]]
then
curl -s "http://web.archive.org/save/$url" > /dev/null
echo "Submitted $url to Wayback Machine"
else
echo "$url (in clipboard) is not valid URL"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment