-
-
Save edsu/aa6f70bb20127b1e18e05dff5e470022 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# Set these environment variables and you can create a (text-only) post using | |
# your favorite command line text editor. | |
# | |
# - EDITOR: e.g. vim, emacs, etc | |
# - MASTODON_POST_HOST: the hostname for our Mastodon account, e.g. chaos.social | |
# - MASTODON_POST_TOKEN: an app access key with write:statuses permission | |
# | |
# See: https://gist.github.com/edsu/aa6f70bb20127b1e18e05dff5e470022 | |
if [[ -z "${EDITOR}" ]]; then | |
echo "⚠️ Please set EDITOR to something (e.g. vim, emacs) in your environment" | |
exit | |
fi | |
if [[ -z "${MASTODON_POST_HOST}" ]]; then | |
echo "⚠️ Please set MASTODON_POST_HOST in your environment" | |
exit | |
fi | |
if [[ -z "${MASTODON_POST_TOKEN}" ]]; then | |
echo "⚠️ Please set MASTODON_POST_TOKEN in your environment, get one by creating an app at https://$MASTODON_POST_HOST/settings/applications" | |
exit | |
fi | |
post_dir=`mktemp -dt "mastodon-post.XXXXXXXXXX"` | |
post_file="$post_dir/post.md" | |
$EDITOR $post_file | |
if [[ ! -f $post_file ]]; then | |
echo "🛑 cancelled posting..." | |
exit | |
fi | |
curl --silent --header "Authorization: Bearer ${MASTODON_POST_TOKEN}" https://${MASTODON_POST_HOST}/api/v1/statuses --form "status=<${post_file}" > /dev/null | |
if [[ $? -eq 0 ]]; then | |
echo "🦣 post sent!" | |
else | |
echo "😟 post failed" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment