]> Git in Space - tootsh/blob - toot
Write 'toot' script
[tootsh] / toot
1 #!/bin/bash
2
3 # send a toot
4
5 # If any arguments are provided, they form the toot, otherwise stdin is used.
6 # If $1 is one of "PUBLIC", "UNLISTED", "PRIVATE", or "DIRECT" (case-sensitive),
7 # then the post visibility is set to that, otherwise $1 stays part of the
8 # resulting toot.
9
10 # config file
11 config="${XDG_CONFIG_HOME:-$HOME/.config}/tootsh-toot"
12
13 # source the "config file"
14 # this needs to set $token and $instance
15 [[ -e "$config" ]] || {
16 echo "Missing config file at $config"
17 exit 1
18 }
19 . "$config"
20
21 # verify config
22 [[ "$token" == "" ]] && {
23 echo '$token'" needs to be set in config file at $config"
24 exit 1
25 }
26 [[ "$instance" == "" ]] && {
27 echo '$instance'" needs to be set in config file at $config"
28 exit 1
29 }
30
31 # post visibility
32 visibility="public"
33 if [[ "$1" == "PUBLIC" ]] ; then
34 shift
35 elif [[ "$1" == "UNLISTED" ]] ; then
36 visibility="unlisted"
37 shift
38 elif [[ "$1" == "PRIVATE" ]] ; then
39 visibility="private"
40 shift
41 elif [[ "$1" == "DIRECT" ]] ; then
42 visibility="direct"
43 shift
44 fi
45
46 # get toot content
47 toot="$@"
48 if [[ "$toot" == "" ]] ; then
49 while read l ; do
50 [[ "$l" == "." ]] && break || toot+="$l\\n"
51 done
52 fi
53
54 echo -n "tooting... "
55
56 itoken="$(echo "$toot" | base64)"
57
58 curl -H "Authorization: Bearer $token" -H "Content-Type: application/json" \
59 -H "Idempotency-Key: $itoken" \
60 -d "{\"status\":\"$toot\",\"visibility\":\"$visibility\"}" \
61 "https://$instance/api/v1/statuses" 2>/dev/null | jq '.url'