Anypaste is a command line pastebin tool that’s not just for plain text. Anypaste supports dozens of hosting sites that accept a variety of different file types, such as images, audio, and video, and has a plugin system to add your favorite hosting site if you find it’s missing. Anypaste is great for sharing content via Reddit, IRC, Discord, Email, forums, or anywhere else that links can go.
anypaste /path/to/fileand several things will happen:
fileand other utilities to determine the type of the file.
Anypaste is written in Bash, and was designed to support Linux and macOS. It should also work on other *nix-y systems, like FreeBSD or the Windows Subsystem for Linux, but some desktop integration features (namely the
--notify command line parameters) will probably have issues.
sudo mkdir -p /usr/local/bin # only needed on macOS sudo curl -Lo /usr/local/bin/anypaste https://anypaste.xyz/sh sudo chmod +x /usr/local/bin/anypaste
Bash, curl, and POSIX core utils are all you need.
ffprobe is optional but can provide more accurate compatibility checking for media file types; typically it comes inside of an
anypaste -has well as here.
-p: Specify part of a plugin name to use.
-t: Comma-separated list of required tags. For example,
-t private,permanentwill only match plugins that keep your file indefinitely and don’t publicly list links.
-f: Skip compatibility checks (force).
-i: Interactive mode. Check it out, super cool!
-n: Specify a custom name for the file (displayed only on certain sites).
-c: Specify a path to a custom configuration file.
-C: Create a default configuration file. Everything will be commented out by default. See Configuration for more info.
--list: List all currently installed plugins in human-readable form. Can be combined with other options, if so it will list the plugins that would otherwise be attempted for upload.
--list-machine: Same as
-l, but for use inside of other scripts. It prints the raw
get_infooutput from each plugin, with a blank line between plugins and at the end.
--notify: See Post-Upload Hooks.
--version: Print version.
--help: Print help text.
export var_name='I am a string'.
export arr_name=('I am a string' 42 'This is the third element').
# don't unset this or everything will break! Not sure why....
export preceding variable names tells Bash to pass these variables to subprocesses. The
export is only necessary when configuring external plugins, i.e plugins that aren’t built-in to Anypaste.
To create your configuration file, run
anypaste -C. It will tell you where the config file was put. It will typically be
~/.config/anypaste.conf on Linux and
~/.anypaste.conf on Mac. Everything is commented out by default.
||List of enabled plugins, in order of precedence||See config file|
||List of hooks that are enabled by default||Empty|
||If set to “greedy”, hooks will be run after every file uploaded. If set to “lazy”, they will only be run just before Anypaste exits.||
||Whether to prettify things with unicode characters. Mainly used in
||Whether to colorize the output.||
||The regular expression to determine which line to copy from when
--copycommand-line options. By default it copies the “main” link, i.e. the one that begins with
Link:. If you wish to copy a different link, say the “direct” links, you can set the
ap_copy_regexconfig option to the regex pattern which will match the line containing the link you want. For direct links, you can do
--notify. It uses
notify-sendon Linux to achieve a cross-desktop-environment experience, but some distros may not ship with it. On Mac, it should “just work” out of the box.
You can change how hooks work when multiple files are uploaded using
ap_hook_policy. If it is set to
lazy (the default), hooks will only run after the last file in a batch. If set to
greedy, they will be run after every file.
Custom hooks can be added to the
ap_hooks array in the config file. They have access to the same environment variables as plugins, but additionally can see the output of the last plugin in
ap_last_stdout. Custom hooks are able to work in combination with built-in plugins; both will run. Example: Adding the following to your config file will save every link uploaded with Anypaste to
ap_hook_policy=greedy ap_hooks=('echo -n "$ap_last_stdout" | grep ^Link: | head -n 1 >> ~/Other/anypaste-links.txt')
chmod +x plugin-file), then put it in
~/.anypaste-plugins(you may need to create this folder). Alternatively, you could put it anywhere in your
$PATH. After that, you must enable the plugin by adding it to the
ap_pluginsarray in your config file. Remember that this array is in order of precedence – if you put it at the end, it will almost never be used!
Want to see your plugin on this list? Open an issue!
|ThinImg||A simple plugin created mainly to serve as an example about how to make third-party plugins. See Making Plugins for more information.||GitHub|
The plugin should determine whether the file being uploaded is compatible with this plugin. Typically, this involves checking that
$ap_mime is a supported MIME type and that
$ap_size is not over the site’s size limit. The plugin should exit with an exit code of
0 if it’s compatible, or non-zero if it is incompatible. This step should not involve any sort of network communications.
The plugin should perform the actual upload. Typically this involves using
curl to upload the file at
$ap_path, using whatever API the site provides. It might also use
$ap_human_name to set the name of the file on the site being uploaded to, if the site supports that. Any warnings, errors, or progress bars should be outputted to stderr. If the upload completes successfully, the plugin should output a blank line to stdout, followed by the links, followed by another blank line. Each “link” should consist of some sort of label, followed by
:, then followed by the actual link. Here’s an example output:
Link: https://imgur.com/abcdef Direct: https://i.imgur.com/abcdef.png Edit: https://imgur.com/edit/abcdef/secret Delete: https://imgur.com/delete/abcdef/secret
Your plugin should try to use “standard” names before the
: whenever possible. This makes Anypaste’s behavior more consistent, and makes it easier to use inside of other scripts. If there’s something special about a link that a user should know, it’s better to output it to stderr before the links rather than stdout with the links. When in doubt, look at the built-in plugins and try to act as similarly to them as possible.
Exit with a code of
0 if the upload was successful, or non-zero otherwise.
The plugin should output “static” information about itself (metadata). Most of the environment variables will not be available during this step. Your plugin should output its information in an ini-like format. Each “section” should start with
[section-name], then any lines after that until the next section are the contents. Blank lines are ignored. For example:
[description] This is a cool plugin for uploading to imgur.com [tags] permanent editable deletable [config] required|imgur_api_public|Public API key requied|imgur_api_secret|Private API secret
List of possible sections:
name: A human-readable name of the plugin. Often just a capitalized version of the machine-readable name.
description: A human-readable description of what this plugin does.
tags: The plugin’s tags, line-separated.
config: Has lines in the format
requiredness|name|description. Each is an additional environment variable/configuration option that the user may supply via
requirednessshould be either
optional, in which case it is purely cosmetic for display in
recommended, which will trigger a warning whenever the plugin is run without that option, and
required, which will consider the plugin incompatible if that option is missing.
nameis the name of the environment variable for this option.
descriptionis cosmetic and human-readable.
Config options are just environment variables which are set in the config file. You don’t have to do anything special to get access to them. Keep in mind that they are in a “global” scope, so name them in a way that they don’t interfere with other config options (e.g, don’t name an option “api_key”; instead, use “imgur_api_key”)
The official example plugin for ThinImg is a great learning resource. However, ThinImg is very simple, and we don’t make use of some of the features plugins can have. If you want to see more fleshed-out plugins, look in the first several hundred lines of the main Anypaste source code – that’s where all the built-in plugins are.
||The absolute path to the uploading file on-disk.|
||The name specified using
||Mime type of the file (from
||Size of the file, in bytes (from
||The name of the plugin as it appears in
||Current Anypaste version.|
There are many other variables set by Anypaste, but they are meant for internal use only and may change without warning.