File: README.md

package info (click to toggle)
madonctl 3.0.2%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 688 kB
  • sloc: sh: 47; makefile: 4
file content (317 lines) | stat: -rw-r--r-- 10,932 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# madonctl

Golang command line interface for the Mastodon API

[![license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://raw.githubusercontent.com/McKael/madonctl/master/LICENSE)

`madonctl` is a [Go](https://golang.org/) CLI tool to use the Mastodon REST API.

It is built on top of [madon](https://github.com/McKael/madon), my Golang
implementation of the API.

## Installation

### Download

Check the [Release page](https://github.com/McKael/madonctl/releases) for some
pre-built binaries.

More pre-built binaries might be available from the [Homepage](https://lilotux.net/~mikael/pub/madonctl/)
(development version and builds for a few other platforms).

### From source

madonctl uses Go modules (dependencies have been vendored for convenience).

You can install the latest `madonctl` release with the usual Go command:

    go install github.com/McKael/madonctl/v3@latest

Or if you want the current master branch:

    go install github.com/McKael/madonctl/v3@master

Alternatively:

    git clone https://github.com/McKael/madonctl
    cd madonctl
    go build    # (or go install)

and you should be able to use `madonctl`.

## Usage

### Configuration

In order to use madonctl, you need to specify the instance name or URL, and
usually provide an account login/password (or a token).

These settings can be passed as command line arguments or environment variables,
but the easiest way is to use a configuration file.

Note that you can **generate a configuration file** for your settings with

`madonctl config dump -i mastodon.social -L username@domain -P password`

(You can redirect the output to a configuration file.)

If you don't want to use the password or if you have enabled *Two-factor
authentication*, you can also use **OAuth2** with the `oauth2` command:

`madonctl -i mastodon.social oauth2 > madonctl.yaml`

For details on the configuration, please check the [configuration](configuration.md) page.

### Usage

The complete list of commands is available in the online help (`madonctl help`,
`madonctl command --help`...) or in the
[manpages](https://lilotux.net/~mikael/pub/madonctl/manual/html/).

### Examples

This is a non-exhaustive list of commands, showing how madonctl works.

To post a simple "toot":
``` sh
% madonctl toot "Hello, World"
```

You can change the toot visibility, add a Content Warning (a.k.a. spoiler)
or send a media file:
``` sh
% madonctl toot --visibility direct "@McKael Hello, you"
% madonctl toot --visibility private --spoiler CW "The answer was 42"
% madonctl post --file image.jpg Selfie # Send a media file
```
Note: The default toot visibility can be set in the configuration file with
the `default_visibility` setting or with the environment variable (example
`export MADONCTL_DEFAULT_VISIBILITY=unlisted`).

Send (text) file content as new message:
```
% madonctl toot --text-file message.txt
```

... or read message from standard input:
```
% echo "Hello from #madonctl" | madonctl toot --stdin
```

Reply to a message:
``` sh
% madonctl toot --in-reply-to 1234 --visibility direct "@user1 @user2 response"
% madonctl toot --in-reply-to 1234 --add-mentions "response"
```
The flag `--add-mentions` automatically adds mentions based on the toot you're
replying to.

Some **account-related commands**:
``` sh
% madonctl accounts blocked                       # List blocked accounts
% madonctl accounts muted                         # List muted accounts

% madonctl account notifications --list --all    # List really all notifications
% madonctl account notifications --list --clear  # List and clear notifications
% madonctl account notifications --notification-id 1234 # Display notification
% madonctl account notifications --dismiss --notification-id 1234
```

Note: By default, madonctl will send a single query.  If you want all available
results you should use the `--all` flag.  If you use a `--limit` value,
madonctl might send several queries until the number of results reaches this
value.

**Update** your account information:
``` sh
% madonctl account update --display-name "John"  # Update display name
% madonctl account update --note "Newcomer"      # Update user note (bio)
% madonctl account update --note ""              # Clear note
% madonctl account update --avatar me.png        # Update avatar

% madonctl account update --bot               # Advertise account as automated
% madonctl account update --default-sensitive # Set medias sensitive by default
% madonctl account update --default-language fra    # Set default toot language
% madonctl account update --default-privacy private # Set default toot privacy
```

See your own **posts**:
``` sh
% madonctl account statuses                      # See last posts
% madonctl account statuses --all                # See all statuses
```

Display accounts you're **following** or your **followers**:
``` sh
% madonctl accounts following                     # See last following
% madonctl accounts following --all               # See all followed accounts
% madonctl accounts followers --limit 30          # Last 30 followers
```

Add/remove a **favourite**, **boost** a status...
``` sh
% madonctl status --status-id 416671 favourite    # Fave a status
% madonctl status --status-id 416671 boost        # Boost (reblog) a status

% madonctl status --status-id 416671 unboost       # Cancel a boost
```

**Pin/unpin** a status...
``` sh
% madonctl status --status-id 533769 pin          # Pin a status
% madonctl status --status-id 533769 unpin        # Unpin a status
```

**Pin/unpin** an account (i.e., account endorsement)...
``` sh
% madonctl status --account-id 1234 pin           # Pin (endorse) an account
% madonctl status --account-id 1234 unpin         # Unpin an account

% madonctl status pin @Gargron@mastodon.social
```

Search for an account (only accounts known to your instance):
``` sh
% madonctl accounts search gargron
```

**Follow** an account with known ID:
``` sh
% madonctl account follow --account-id 1234
```

Follow a remote account:
``` sh
% madonctl account follow --remote Gargron@mastodon.social
```

madonctl 2.3.0+ is able to recognize the kind of argument to specify and to
use the relevant API calls, so the previous commands could be written as:
``` sh
% madonctl account follow 1234
% madonctl account follow Gargron@mastodon.social
% madonctl account follow https://mastodon.social/@Gargron
```

Note: If you know the numeric account ID, you should use it to save extra API
calls.

**Search** for accounts, statuses or hashtags:
``` sh
% madonctl search gargron
% madonctl search mastodon
```

When the account ID is unknown, --user-id can be useful.\
You can specify the (instance-specific) account ID number (--account-id) or
the user ID (--user-id).  In the later case, madonctl will search for the
user so it must match exactly the ID known to your instance (without the
@domain suffix if the user is on the same instance).  The --user-id flag can
also contain an HTTP account URL.
``` sh
% madonctl account --user-id Gargron@mastodon.social -l5 statuses # Last 5 statuses
% madonctl account --user-id https://mastodon.social/@Gargron -l5 statuses # Same
```

With madonctl 2.3.0+, you can use the shorter forms:
``` sh
% madonctl account statuses -l5 Gargron@mastodon.social
% madonctl account statuses -l5 https://mastodon.social/@Gargron
% madonctl account statuses -l5 1   # (account ID)
```

Please note that the form "Gargron@mastodon.social" will only work if this
account is known by the instance.  If it is unknown, the https link should work
(and the Mastodon server will learn about the account).

Read **timelines**:
``` sh
% madonctl timeline                 # Display home timeline
% madonctl timeline home            # (same as previous command)
% madonctl timeline public          # Display federated timeline
% madonctl timeline public --local  # Display public local timeline
% madonctl timeline direct          # Display timeline of direct messages

% madonctl timeline --limit 3       # Display 3 latest home timeline messages
```

Use the **streaming API** and fetch timelines and notifications:
``` sh
% madonctl stream                   # Stream home timeline and notifications
% madonctl stream local             # Stream local timeline
% madonctl stream public            # Stream federated timeline
% madonctl stream direct            # Stream direct messages
```

You can also use **hashtag streams**:
``` sh
% madonctl stream :mastodon         # Stream for hastag 'mastodon'
% madonctl stream :madonctl,golang  # Stream for several hashtags
```

Please note that madonctl will use one socket per stream, so the number of
concurrent hashtags is currently limited to 4 for "politeness".

It is also possible to send every stream event (notification or status) to
an **external command**.  You can can even combine it with a customized theme.
The contents will be sent to the standard input of this command:
``` sh
madonctl stream --command gateway.sh --theme gateway
```

(Almost) All commands have a **customizable output**:
``` sh
% madonctl account show            # Display an account
% madonctl account show -o yaml    # Display an account, in yaml
% madonctl account show -o json    # Display an account, in json
% madonctl stream local -o json     # Stream local timeline and output to JSON
```

You can also use Go (Golang) **templates**:
``` sh
% madonctl account --account-id 1 followers --template '{{.acct}}{{"\n"}}'
```

You can write and use [themes](templates) as well:
```
madonctl --theme=ansi timeline
```

There are many more commands, you can find them in the online help or the manpage.


### Shell completion

If you want **shell completion**, you can generate scripts with the following command: \
`madonctl completion bash` (or zsh)

Then, just source the script in your shell.

For example, I have this line in my .zshrc:

`source <(madonctl completion zsh)`

### Commands output

The output can be set to **json**, **yaml** or to a **Go template** for all commands.\
If you are familiar with Kubernetes' kubectl, it is very similar.

For example, you can display your user token with:\
`madonctl config whoami --template '{{.access_token}}'`\
or the application ID with:\
`madonctl config dump --template '{{.ID}}'`

All the users that have favorited a given status:\
`madonctl status --status-id 101194 favourited-by --template '{{.username}}{{"\n"}}'`

Sets of templates can be grouped as **themes**.

For more complex templates, one can use the `--template-file` option.\
See the [themes & templates](templates) folder.

## References

- [madonctl manpages](https://lilotux.net/~mikael/pub/madonctl/manual/html/)
- [madon](https://github.com/McKael/madon), the Go library for Mastodon API
- [Mastodon API documentation](https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md)
- [Mastodon repository](https://github.com/tootsuite/mastodon)