diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 17:42:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 17:42:51 +0000 |
commit | ba429d344132c088177e853cce8ff7181570b221 (patch) | |
tree | 87ebf15269b4301737abd1735baabba71be93622 /plugins/externaltools/data/send-to-fpaste.tool.in | |
parent | Initial commit. (diff) | |
download | gedit-upstream/44.2.tar.xz gedit-upstream/44.2.zip |
Adding upstream version 44.2.upstream/44.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-x | plugins/externaltools/data/send-to-fpaste.tool.in | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/plugins/externaltools/data/send-to-fpaste.tool.in b/plugins/externaltools/data/send-to-fpaste.tool.in new file mode 100755 index 0000000..d392173 --- /dev/null +++ b/plugins/externaltools/data/send-to-fpaste.tool.in @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +import os, urllib, json, sys, urllib.request +from gi.repository import Gtk, Gdk + +text = sys.stdin.read() + +lang = os.getenv('GEDIT_CURRENT_DOCUMENT_LANGUAGE') +if lang is None: + lang = "text" + +url_params = urllib.parse.urlencode({'paste_data': text, 'paste_lang': lang, 'mode':'json', 'api_submit':'true'}) +openfpaste = urllib.request.urlopen("http://fpaste.org", bytes(url_params, 'utf-8')).read().decode("utf-8") +if openfpaste is None: + print("Failed to send fpaste request.") + +final_data = json.loads(openfpaste) + +paste_url = "http://fpaste.org/" + final_data['result']['id'] + +disp = Gdk.Display.get_default() +clipboard = Gtk.Clipboard.get_for_display(disp, Gdk.SELECTION_CLIPBOARD) +clipboard.set_text(paste_url, len(paste_url)) +clipboard.store() + +print(paste_url + " has been copied to the clipboard.") |