| Name | poly-cli JSON |
| Version |
1.1.0
JSON |
| download |
| home_page | None |
| Summary | CLI tool for text and clipboard manipulation |
| upload_time | 2024-09-05 04:02:30 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.12 |
| license | None |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# Poly
A simple command for converting and processing data from your clipboard.
## Installation
### Via `pip`
**Poly** is available on PyPi under the name `poly-cli`. To install it, simply do
```bash
python3 -m pip install poly-cli
```
### Via `pipx`
**From Python 3.12 and on, especially on Mac, you are warned against/forbidden from installing
Python packages in an "externally-managed" environment (AKA in user space).**
PIP will recommend that you install things using `pipx` which should manage virtual environments for you.
To install **Poly** this way, the interface is the same, so simply do
```bash
pipx install poly-cli
```
From this point on, the **Poly** CLI can be accessed with the cli command `poly`. See "Usage" below
## Environment Variable Config
There are environment variables you can set to control the behavior of **Poly**:
### `POLY_CFG_COLOR`
**Default: `1`**
Setting this value to `0` will result in no syntax highlighting for output containing JSON/YAML/TOML.
## Usage
This script will expect you to have the text it will manipulate in your clipboard.
When you run a command, it will do its job, and if it is successful,
**it will put the modified text back into your clipboard**, as well as send it
to stdout.
You can generally convert data with the following format:
`poly <from_format> <to_format>[ options]`
Any other generic command is simply
`poly <command>[ options]`
You can find some basic help from the `--help` option at any level:
```sh
poly --help
poly json --help
poly yaml --help
...etc
```
## Chat Copypasta
A slowly-expanding list of chat programs to copy/paste out of into a
more sane a readable format (thanks, emoji reactions...)
The intention is for each command to support both the webapp and the desktop client
for each of the chat programs (Yes, they copy differently. No, you shouldn't be surprised.)
Supported chat program(s):
- Slack
Future support:
- Discord
- MS Teams
## Conversions
All of the following formats convert between each other:
- JSON
- YAML
- TOML
- JWT
- URL Query String (see below for what this means)
**NOTE: Some data types (like `null` in TOML) won't convert and might be dropped!**
Additionally, you can convert between color formats:
- Hex _(e.g. `#123`, `#123456`, `#1234`, `#12345678`)_
- RGB _(e.g. `(10, 10, 10)`, `(5,5,5)`)_
- RGBA _(e.g. `(10, 10, 10, 10)`, `(5,5,5,5)`)_
### JWT Conversion
Converting to JWT requires two additional options:
- `-s, --secret`: A secret string to encode/decode with
- `-a, --algorithm`: An algorithm to encode/decode with
### URL Query String Type Conversion
When converting from a query string you can use the `-c, --convert` flag to tell `poly` to attempt to convert
all the values in the query string. They all start as strings, but it will attempt to do things like convert `"true"` to `true` for JSON/YAML, etc.
This only works for the basic data types; it will not do anything smart like nested objects/lists.
_Example:_
assuming your clipboard contains `a=1&b=true&c=a,b,c`...
```sh
poly query-string json --convert
```
will result in
```json5
{
"a": 1,
"b": true,
"c": "a,b,c" // note that this is NOT ["a", "b", "c"]
}
```
`?foo=bar,baz,bat` will be converted as a string of `{"foo": "bar,baz,bat"}`, not as a list of `{"foo": ["bar", "baz", "bat"]}`
If you want a list to be built, simply use the same query param multiple times.
More complex example (including list and complex object):
assuming your clipboard contains
```
http://foo.bar.com?a=1&b=true&c=a,b,c&b=false&d={"foo":"bar"}
```
_(note that this contains a url! oooooo....)_
running:
```sh
poly query-string json --convert --include-url
```
will result in:
```json5
{
"url": "http://foo.bar.com", // from --include-url
"a": 1,
"b": [true, false], // multiple 'b' params were combined into a list
"c": "a,b,c", // note that this is NOT ["a", "b", "c"]
"d": {"foo": "bar"} // oooooo fancy
}
```
This is all done using the Python builtin `ast.literal_eval()` -- a completely safe function that will attempt simply to convert the string to a valid Python literal, but **does not execute the string as code.**
## JSON formatting (`json`)
Manipulate JSON data from the clipboard
All commands start with `poly json`
- `pretty`: pretty-prints the JSON in your clipboard and sends it back to the clipboard
- `one-line`: outputs the JSON in your clipboard as a single line of text and sends it back to the clipboard
## Base64 (`b64`)
Encode/Decode Base64 data
- `poly b64 from`: Takes base64-encoded data from the clipboard, outputs the decoded data, and sends it back to the clipboard
- `poly b64 to`: Takes data from the clipboard, outputs base64-encoded data, and sends it back to the clipboard
## Hash Functions
Supports `md5`, `sha1`, `sha256`, and `sha512`
## URL Query Param Encoding/Decoding
- `poly url encode`
- `poly url decode`
Encodes strings like
```
a=1&b=true&c=a,b,c&b=false&d={"foo": "bar", "baz": "bat"}
```
into
```
a=1&b=true&b=false&c=a%2Cb%2Cc&d=%7B%22foo%22%3A%20%22bar%22%2C%20%22baz%22%3A%20%22bat%22%7D
```
and decodes them back again.
Both `encode`/`decode` also support `-q, --quote-plus` which allows for encoding spaces as `+` instead of `%20`
## String Manipulation
- **Line sorting (`line-sort`)**: This will attempt to sort the lines of a `\n`-separated string in your clipboard
- **Spongebob (`sponge`, `spongebob`)**: _I WoNDeR What ThIS doEs_
- **Smart Quotes (`quotes`)**: Replaces those stupid `“`/`”`/`‘`/`’` with proper quotes `"`/`'`
- **[Un]Escape Text (`escape`/`unescape`)**: Add/remove `\` in a string for given characters
Raw data
{
"_id": null,
"home_page": null,
"name": "poly-cli",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.12",
"maintainer_email": "poly@3digit.dev",
"keywords": null,
"author": null,
"author_email": "poly@3digit.dev",
"download_url": "https://files.pythonhosted.org/packages/97/ea/0e3fdb1782a1df987d58dd66d000ad40d98c696c0a52673eadae03e4f7aa/poly_cli-1.1.0.tar.gz",
"platform": null,
"description": "# Poly\n\nA simple command for converting and processing data from your clipboard.\n\n## Installation\n\n### Via `pip`\n\n**Poly** is available on PyPi under the name `poly-cli`. To install it, simply do\n\n```bash\npython3 -m pip install poly-cli\n```\n\n### Via `pipx`\n\n**From Python 3.12 and on, especially on Mac, you are warned against/forbidden from installing\nPython packages in an \"externally-managed\" environment (AKA in user space).**\n\nPIP will recommend that you install things using `pipx` which should manage virtual environments for you.\n\nTo install **Poly** this way, the interface is the same, so simply do\n\n```bash\npipx install poly-cli\n```\n\nFrom this point on, the **Poly** CLI can be accessed with the cli command `poly`. See \"Usage\" below\n\n## Environment Variable Config\n\nThere are environment variables you can set to control the behavior of **Poly**:\n\n### `POLY_CFG_COLOR`\n\n**Default: `1`**\n\nSetting this value to `0` will result in no syntax highlighting for output containing JSON/YAML/TOML.\n\n## Usage\n\nThis script will expect you to have the text it will manipulate in your clipboard.\nWhen you run a command, it will do its job, and if it is successful, \n**it will put the modified text back into your clipboard**, as well as send it\nto stdout.\n\nYou can generally convert data with the following format:\n\n`poly <from_format> <to_format>[ options]`\n\nAny other generic command is simply\n\n`poly <command>[ options]`\n\nYou can find some basic help from the `--help` option at any level:\n\n```sh\npoly --help\npoly json --help\npoly yaml --help\n...etc\n```\n\n## Chat Copypasta\n\nA slowly-expanding list of chat programs to copy/paste out of into a \nmore sane a readable format (thanks, emoji reactions...)\n\nThe intention is for each command to support both the webapp and the desktop client\nfor each of the chat programs (Yes, they copy differently. No, you shouldn't be surprised.)\n\nSupported chat program(s):\n\n- Slack\n\nFuture support:\n\n- Discord\n- MS Teams\n\n## Conversions\n\nAll of the following formats convert between each other:\n\n- JSON\n- YAML\n- TOML\n- JWT\n- URL Query String (see below for what this means)\n\n**NOTE: Some data types (like `null` in TOML) won't convert and might be dropped!**\n\nAdditionally, you can convert between color formats:\n\n- Hex _(e.g. `#123`, `#123456`, `#1234`, `#12345678`)_\n- RGB _(e.g. `(10, 10, 10)`, `(5,5,5)`)_\n- RGBA _(e.g. `(10, 10, 10, 10)`, `(5,5,5,5)`)_\n\n### JWT Conversion\n\nConverting to JWT requires two additional options:\n\n- `-s, --secret`: A secret string to encode/decode with\n- `-a, --algorithm`: An algorithm to encode/decode with\n\n### URL Query String Type Conversion\n\nWhen converting from a query string you can use the `-c, --convert` flag to tell `poly` to attempt to convert\nall the values in the query string. They all start as strings, but it will attempt to do things like convert `\"true\"` to `true` for JSON/YAML, etc.\nThis only works for the basic data types; it will not do anything smart like nested objects/lists.\n\n_Example:_\n\nassuming your clipboard contains `a=1&b=true&c=a,b,c`...\n\n```sh\npoly query-string json --convert\n```\n\nwill result in\n```json5\n{\n \"a\": 1,\n \"b\": true,\n \"c\": \"a,b,c\" // note that this is NOT [\"a\", \"b\", \"c\"]\n}\n```\n\n`?foo=bar,baz,bat` will be converted as a string of `{\"foo\": \"bar,baz,bat\"}`, not as a list of `{\"foo\": [\"bar\", \"baz\", \"bat\"]}`\nIf you want a list to be built, simply use the same query param multiple times.\n\nMore complex example (including list and complex object):\n\nassuming your clipboard contains\n```\nhttp://foo.bar.com?a=1&b=true&c=a,b,c&b=false&d={\"foo\":\"bar\"}\n```\n_(note that this contains a url! oooooo....)_\n\nrunning:\n```sh\npoly query-string json --convert --include-url\n```\n\nwill result in:\n```json5\n{\n \"url\": \"http://foo.bar.com\", // from --include-url\n \"a\": 1,\n \"b\": [true, false], // multiple 'b' params were combined into a list\n \"c\": \"a,b,c\", // note that this is NOT [\"a\", \"b\", \"c\"]\n \"d\": {\"foo\": \"bar\"} // oooooo fancy\n}\n```\n\nThis is all done using the Python builtin `ast.literal_eval()` -- a completely safe function that will attempt simply to convert the string to a valid Python literal, but **does not execute the string as code.**\n\n## JSON formatting (`json`)\n\nManipulate JSON data from the clipboard\n\nAll commands start with `poly json`\n\n- `pretty`: pretty-prints the JSON in your clipboard and sends it back to the clipboard\n- `one-line`: outputs the JSON in your clipboard as a single line of text and sends it back to the clipboard\n\n## Base64 (`b64`)\n\nEncode/Decode Base64 data\n\n- `poly b64 from`: Takes base64-encoded data from the clipboard, outputs the decoded data, and sends it back to the clipboard\n- `poly b64 to`: Takes data from the clipboard, outputs base64-encoded data, and sends it back to the clipboard\n\n## Hash Functions\n\nSupports `md5`, `sha1`, `sha256`, and `sha512`\n\n## URL Query Param Encoding/Decoding\n\n- `poly url encode`\n- `poly url decode`\n\nEncodes strings like\n\n```\na=1&b=true&c=a,b,c&b=false&d={\"foo\": \"bar\", \"baz\": \"bat\"}\n```\n\ninto\n\n```\na=1&b=true&b=false&c=a%2Cb%2Cc&d=%7B%22foo%22%3A%20%22bar%22%2C%20%22baz%22%3A%20%22bat%22%7D\n```\n\nand decodes them back again.\n\nBoth `encode`/`decode` also support `-q, --quote-plus` which allows for encoding spaces as `+` instead of `%20`\n\n\n## String Manipulation\n\n- **Line sorting (`line-sort`)**: This will attempt to sort the lines of a `\\n`-separated string in your clipboard\n- **Spongebob (`sponge`, `spongebob`)**: _I WoNDeR What ThIS doEs_\n- **Smart Quotes (`quotes`)**: Replaces those stupid `\u201c`/`\u201d`/`\u2018`/`\u2019` with proper quotes `\"`/`'`\n- **[Un]Escape Text (`escape`/`unescape`)**: Add/remove `\\` in a string for given characters\n",
"bugtrack_url": null,
"license": null,
"summary": "CLI tool for text and clipboard manipulation",
"version": "1.1.0",
"project_urls": {
"Homepage": "https://github.com/3digitdev/poly",
"Issues": "https://github.com/3digitdev/poly/issues"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7ba621900f256f89b286e19898dc2b6d397ddb529b9da7c46259a2e22c86aaca",
"md5": "89868b1965dc44652e5966ea6f1701bb",
"sha256": "e0432ac49adb3c903a1d2caf274874e1bb01c5fd09fef0c82ea60bcb56745a76"
},
"downloads": -1,
"filename": "poly_cli-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "89868b1965dc44652e5966ea6f1701bb",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.12",
"size": 21771,
"upload_time": "2024-09-05T04:02:29",
"upload_time_iso_8601": "2024-09-05T04:02:29.342096Z",
"url": "https://files.pythonhosted.org/packages/7b/a6/21900f256f89b286e19898dc2b6d397ddb529b9da7c46259a2e22c86aaca/poly_cli-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "97ea0e3fdb1782a1df987d58dd66d000ad40d98c696c0a52673eadae03e4f7aa",
"md5": "8db9b9a34431afa0b79220a17663f45e",
"sha256": "19fe3fac4c7caab7a23a20344de9597bfee93bbc7f955bb5bb1beadd94e2d4b3"
},
"downloads": -1,
"filename": "poly_cli-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "8db9b9a34431afa0b79220a17663f45e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.12",
"size": 22993,
"upload_time": "2024-09-05T04:02:30",
"upload_time_iso_8601": "2024-09-05T04:02:30.919744Z",
"url": "https://files.pythonhosted.org/packages/97/ea/0e3fdb1782a1df987d58dd66d000ad40d98c696c0a52673eadae03e4f7aa/poly_cli-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-05 04:02:30",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "3digitdev",
"github_project": "poly",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "poly-cli"
}