feat(zsh): add script for paste.sr.ht

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2022-11-19 15:14:47 +01:00
parent 417a8a747e
commit 95a8a950b5
Signed by: mfocko
GPG key ID: 7C47D46246790496
2 changed files with 50 additions and 0 deletions

View file

@ -43,3 +43,14 @@
template: template:
src: templates/scripts/toolbox_name.sh src: templates/scripts/toolbox_name.sh
dest: ~/.local/bin/toolbox_name.sh dest: ~/.local/bin/toolbox_name.sh
- name: Install script for paste.sr.ht
template:
src: templates/scripts/srht.py
dest: ~/.local/bin/srht.py
- name: Symlink paste.sr.ht
ansible.builtin.file:
src: ./srht.py
dest: ~/.local/bin/srht
state: link

View file

@ -0,0 +1,39 @@
#!/usr/bin/env python3
import os
import click
import requests
@click.command()
@click.option("--public", "visibility", flag_value="public")
@click.option("--unlisted", "visibility", flag_value="unlisted", default=True)
@click.option("--private", "visibility", flag_value="private")
@click.argument("src", type=click.File("r"), nargs=-1)
def paste(visibility, src):
request = {
"visibility": visibility,
"files": [
{"filename": s.name.split("/")[-1], "contents": s.read()}
for s in src
],
}
response = requests.post(
"https://paste.sr.ht/api/pastes",
json=request,
headers={"Authorization": f"token {os.getenv('SRHT_LEGACY')}"},
).json()
if "sha" in response:
click.secho(
f"Pasted: https://paste.sr.ht/~mfocko/{response['sha']}",
fg="green",
)
else:
click.secho(response, fg="red")
if __name__ == "__main__":
paste()