[gedit] Add external tools plugin script: Send to fpaste



commit 349201e4bbb2d84934915cf293d6122894feb5d1
Author: Sindhu S <sindhus live in>
Date:   Sat Nov 30 13:14:32 2013 +0530

    Add external tools plugin script: Send to fpaste

 plugins/externaltools/data/Makefile.am             |    1 +
 .../externaltools/data/send-to-fpaste.desktop.in   |   11 +++++++++
 plugins/externaltools/data/send-to-fpaste.tool.in  |   24 ++++++++++++++++++++
 3 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/plugins/externaltools/data/Makefile.am b/plugins/externaltools/data/Makefile.am
index bafa78f..04eeb75 100644
--- a/plugins/externaltools/data/Makefile.am
+++ b/plugins/externaltools/data/Makefile.am
@@ -3,6 +3,7 @@ EXTERNALTOOLS_TOOL_MERGE = $(top_srcdir)/plugins/externaltools/scripts/gedit-too
 externaltools_tools_in_files =                                         \
        plugins/externaltools/data/build.tool.in                        \
        plugins/externaltools/data/remove-trailing-spaces.tool.in
+       plugins/externaltools/data/send-to-fpaste.tool.in
 
 externaltools_tools_in_linux =                                         \
        plugins/externaltools/data/open-terminal-here.tool.in           \
diff --git a/plugins/externaltools/data/send-to-fpaste.desktop.in 
b/plugins/externaltools/data/send-to-fpaste.desktop.in
new file mode 100644
index 0000000..e6ae095
--- /dev/null
+++ b/plugins/externaltools/data/send-to-fpaste.desktop.in
@@ -0,0 +1,11 @@
+[Gedit Tool]
+_Name=Send to fpaste
+_Comment=Paste selected text or current document to fpaste
+Input=selection-document
+Output=output-panel
+Shortcut=<Shift><Super>p
+Applicability=always
+Save-files=nothing
+Languages=
+
+
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..372a6c0
--- /dev/null
+++ b/plugins/externaltools/data/send-to-fpaste.tool.in
@@ -0,0 +1,24 @@
+#!/bin/env python3
+
+import os, urllib, json, sys, urllib.request
+from gi.repository import Gtk, Gdk
+
+lang = os.getenv('GEDIT_CURRRENT_DOCUMENT_LANGUAGE')
+current_document_path = os.getenv('GEDIT_CURRENT_DOCUMENT_PATH')
+selected_text = os.getenv('GEDIT_SELECTED_TEXT')
+
+if selected_text is None:
+    selected_text = sys.stdin.read()
+
+url_params = urllib.parse.urlencode({'paste_data': selected_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")
+final_data = json.loads(openfpaste)
+
+paste_url = "http://fpaste.org/"; + final_data['result']['id']
+
+print(paste_url + " has been copied to clipboard.")
+
+disp = Gdk.Display.get_default()
+clipper = Gtk.Clipboard.get_for_display(disp, Gdk.SELECTION_CLIPBOARD)
+clipper.set_text(paste_url, len(paste_url))
+clipper.store()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]