Documentation Plugins GitHub Install

Documentation

This is the official documentation for Anypaste. Found a grammar mistake or something unclear? Contribute to this on the anypaste-website repo.

Installation
Anypaste is just a single executable file/shell script. It's hosted at anypaste.xyz/sh, or you can download it from the GitHub repo. Put it somewhere where you can run it (/usr/bin/anypaste is a nice spot), mark it executable, then you're ready to go! The quickest way to install is just the following command: sudo curl -o /usr/bin/anypaste https://anypaste.xyz/sh && sudo chmod +x /usr/bin/anypaste

To update anypaste, just overwrite the old executable with the new one. If new plugins were added in a release, you have two options: either delete your config file, and anypaste will create a new one with the new plugins enabled automatically, or you can manually add the new plugins to ap_plugins in your config file.
Basic Usage
Upload a single file: anypaste /path/filename
Upload multiple files: anypaste /path/file1 /path/file2
Upload stdin: echo 'Upload me!' | anypaste
Upload files and stdin: echo 'Upload me!' | anypaste - /path/file1 /path/file2

All of these commands will pick the "best" plugin automatically: The first one listed in your config file that's compatible with the specified file. There are situations, however, where you'll want to override this behavior, such as if you want to use a certain plugin or use an incompatible plugin.

Upload with a specific plugin: anypaste -p gfycat /path/filename
Upload with a specific plugin, bypassing compatibility checks: anypaste -fp gfycat /path/filename
Upload with a specific plugin, even if its not in the config file: anypaste -xp gfycat /path/filename
Upload with interactive mode, which will prompt about which plugin to use: anypaste -i /path/filename

For more in-depth information about command-line options, run anypaste -h to display the built-in help text.
Config
Anypaste uses a configuration file to disable or enable plugins and provide extra options to plugins. As of Anypaste 1.0.3, it operates without a config file by default. If you want to use a config file, create a default one by running anypaste -C. It will tell you where it was placed (usually ~/.config/anypaste.conf on Linux and ~/.anypaste.conf on Mac). The default file is fairly self-explanatory, you should be able to figure out how to use it based on the comments in it.

The anypaste config file is just a simple shell script that sets variables. Here's a primer on how to set variables:
Arrays: export arr_name=('arr_val_1' 'arr_val_2' 'arr_val_3') (you don't need export for ap_plugins)
Strings: export var_name='var_value'
Comments: # Comments here

The main configuration option you'll want to deal with is ap_plugins. It's an array of enabled plugins. If multiple plugins are compatible, the first one will be used, so order matters. It's the only option which doesn't need export before it. You can find a list of plugins and options they support here.
Using Plugins
Each upload site in Anypaste is represented by a plugin. Each plugin is an executable file (except for the built-in ones, they're special). It's recommended to put plugin executables in ~/.anypaste-plugins (you'll need to create the folder). So, the basic procedure for installing a plugin is:
  1. Create ~/.anypaste-plugins if it does not yet exist: mkdir -p ~/.anypaste-plugins
  2. Download the plugin executable into ~/.anypaste-plugins: curl -o ~/.anypaste-plugins/example example.com/example
  3. Mark the plugin as executable: chmod +x ~/.anypaste-plugins/example
  4. Add the plugin to the ap_plugins array in your config file: vim ~/.config/anypaste.conf
Anypaste uses the ap_plugins array in your config file to determine which plugins are enabled. You need to add new plugins to it, and can disable built-in plugins by removing them from it.
Authenticating to Plugins
Some plugins, such as Streamable and Docdroid, do not work out-of-the-box. Streamable requires an account (no anonymous uploading), and Docdroid needs an API key. These are called "Authenticated Plugins" because they need authentication to function. You can authenticate by placing authentication information into anypaste.conf. The exact way to do this varies by plugin. With streamable, you need to set the streamable_email and streamable_password options in your config file to the email and password for your Streamable account. For example:

export streamable_email='spamhereplease@markasoftware.com'
export streamable_password='hunter2'


There are some comments in the default config file to help walk you through this.
Developing Plugins
Creating a plugin for Anypaste is fairly simple. Just create an executable which takes a single command-line argument, and can read environment variables. Here are the different things that may be passed as a command-line argument, and what you should do for each one:

get_required_config: Your plugin should return a newline-separated list of required configuration options. If these options are not set, your plugin will be considered incompatible, and the user will be prompted.

check_eligibility: Your plugin should check whether the current file is compatible. The absolute path to the file will be in the environment variable ap_path, and the mime type of the file (determined using file --mime-type) will be in ap_mime. It's ok for your plugin to print some sort of message if the file is "almost" compatible (for example, correct file type but over size limit).

upload: Your plugin should upload the current file (in env variable ap_path). Assume that the file has already been checked for compatibility.

This might seem a bit confusing, and it is! The easiest way to learn how plugins work and how to make one is to look at the built-in plugins in the source code or the example plugin for MAGAimg.net