summaryrefslogtreecommitdiffstats
path: root/plugins/externaltools/data/send-to-fpaste.tool.in
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 14:32:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 14:32:59 +0000
commitadb934701975f6b0214475d1a8d0d1ce727b9d4d (patch)
tree5688c745d10b64c8856586864ec416a6bdae881d /plugins/externaltools/data/send-to-fpaste.tool.in
parentInitial commit. (diff)
downloadgedit-adb934701975f6b0214475d1a8d0d1ce727b9d4d.tar.xz
gedit-adb934701975f6b0214475d1a8d0d1ce727b9d4d.zip
Adding upstream version 3.38.1.upstream/3.38.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'plugins/externaltools/data/send-to-fpaste.tool.in')
-rwxr-xr-xplugins/externaltools/data/send-to-fpaste.tool.in26
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.")