#!/bin/sh # toot with curl # usage examples: # pwet 'This is a new status' # pwet 'This is a reply to a post <@https://url.tld/@username/post_id>' # # For replies, you have to put in your status between "<@" and ">" the url of the status. # It is a good idea to quote the status to avoid shell surprises # configuration mastodon_instance="im-in.space" # create a new application in your mastodon profile to get a token # write it in the file mentionned below in token_file token_file=~/.config/pwet.token if [ ! -f "${token_file}" ]; then cat << EOF You need a token to use pwet with your mastodon account. In your mastodon profile, open "Development" menu and create a "New application". Copy the generated "token" in ${token_file} EOF fi ### token="$(cat ${token_file})" mastodon_url="https://${mastodon_instance}/api/v1/statuses" status="\"$*\"" # stop here if there is nothing to say test -z "${status}" && exit # FIXME? awk below seems weak # get status id if there is a reply to a post reply_id="$(printf "%s" "${status}" | awk ' match($0, /<@.*:\/\/.*\/([0-9]+)>/) { mention = substr($0, RSTART, RLENGTH) match(mention, /\/([0-9]+)>/) id = substr(mention, RSTART+1, RLENGTH-2) print id } ')" if [ -z "${reply_id}" ]; then # not a reply curl -s "${mastodon_url}" \ -H "Authorization: Bearer $token" \ -F status="${status}" >/dev/null else # reply curl -s "${mastodon_url}" \ -H "Authorization: Bearer $token" \ -F status="${status}" \ -F in_reply_to_id="${reply_id}" >/dev/null fi exit $?