feat(zsh): add script for paste.sr.ht
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
417a8a747e
commit
95a8a950b5
2 changed files with 50 additions and 0 deletions
|
@ -43,3 +43,14 @@
|
|||
template:
|
||||
src: templates/scripts/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
|
||||
|
|
39
playbooks/roles/shell/templates/scripts/srht.py
Executable file
39
playbooks/roles/shell/templates/scripts/srht.py
Executable 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()
|
Loading…
Reference in a new issue