Browse Source

Initial commit

tags/0.0.1^0
Kim Grytøyr 7 months ago
commit
85b0d82a55
Signed by: Kim Grytøyr <kim@grytoyr.io> GPG Key ID: 759EF8C94E0B45B7

+ 7
- 0
Context.sublime-menu View File

@@ -0,0 +1,7 @@
1
+[
2
+{
3
+    "id" : "npasteUpload",
4
+    "caption" : "Paste to npaste",
5
+    "command" : "npaste_upload"
6
+}
7
+]

+ 6
- 0
Default (Linux).sublime-keymap View File

@@ -0,0 +1,6 @@
1
+[
2
+{ 
3
+  "keys": ["ctrl+alt+p"],
4
+  "command": "npaste_upload"
5
+}
6
+]

+ 6
- 0
Default (OSX).sublime-keymap View File

@@ -0,0 +1,6 @@
1
+[
2
+{ 
3
+  "keys": ["super+alt+n"],
4
+  "command": "npaste_upload"
5
+}
6
+]

+ 6
- 0
Default (Windows).sublime-keymap View File

@@ -0,0 +1,6 @@
1
+[
2
+{ 
3
+  "keys": ["ctrl+alt+p"],
4
+  "command": "npaste_upload"
5
+}
6
+]

+ 7
- 0
dependencies.json View File

@@ -0,0 +1,7 @@
1
+{
2
+   "*": {
3
+      "*": [
4
+         "requests"
5
+      ]
6
+   }
7
+}

+ 57
- 0
npaste-upload.py View File

@@ -0,0 +1,57 @@
1
+import sublime
2
+import sublime_plugin
3
+import os
4
+import uuid
5
+import string
6
+import random
7
+import base64
8
+import requests
9
+from subprocess import *
10
+from requests.auth import HTTPBasicAuth
11
+
12
+class NpasteUploadCommand(sublime_plugin.TextCommand):
13
+  def run(self, edit):
14
+    settings = sublime.load_settings('npaste.sublime-settings')
15
+    selection = self.view.sel()
16
+    selections = "\n".join(list(map(lambda s: self.view.substr(s), selection)))
17
+
18
+    if selections == "":
19
+      npaste_data = self.view.substr(sublime.Region(0, self.view.size()))
20
+    else:
21
+      npaste_data = selections
22
+
23
+    data = ""
24
+    passphrase = None
25
+    payload = {'age': settings.get('npaste.age') }
26
+
27
+    # Encrypt paste using GPG
28
+    if (settings.get('npaste.encrypt') == True):
29
+      passphrase = ''.join(random.SystemRandom().choice(string.ascii_lowercase + string.digits) for _ in range(settings.get('npaste.encryption_key_length')))
30
+
31
+      process = Popen(['gpg', '--armor', '--batch', '--passphrase', passphrase, '--symmetric'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
32
+      d = bytes(npaste_data, 'utf-8')
33
+      process.stdin.write(base64.b64encode(bytes(npaste_data, 'utf-8')))
34
+      paste, errs = process.communicate()
35
+
36
+      if (not errs):
37
+        data = paste.decode("utf-8")
38
+        payload["encrypted"] = 1
39
+      else:
40
+        sublime.message_dialog(errs.decode("utf-8"))
41
+    else:
42
+      data = npaste_data
43
+
44
+    if settings.get('npaste.archive') == True:
45
+      payload["archive"] = 1
46
+
47
+    # Upload paste to npaste
48
+    files = {'paste': ('paste.txt', data, 'text/plain')}
49
+    r = requests.post(settings.get('npaste.url'), files=files, data=payload, auth=HTTPBasicAuth(settings.get('npaste.username'), settings.get('npaste.password')))
50
+
51
+    url = r.text
52
+
53
+    if (passphrase is not None):
54
+      url = url + "#" + passphrase
55
+
56
+    sublime.set_clipboard(url)
57
+    sublime.message_dialog('Copied to clipboard!')

+ 22
- 0
settings/npaste.sublime-settings View File

@@ -0,0 +1,22 @@
1
+{
2
+//  Specifies the URL of the npaste server to use
3
+    "npaste.url": "http://localhost:3000/",
4
+
5
+//  Specifies the npaste API username
6
+    "npaste.username": "user",
7
+
8
+//  Specifies the npaste API password
9
+    "npaste.password": "password",
10
+
11
+//  If true, pastes will be archived instead of deleted when they expire.
12
+    "npaste.archive": true,
13
+
14
+//  Sets the age of pastes (s,m,h,d,y)
15
+    "npaste.age": "14d",
16
+
17
+//  If true, pastes will be encrypted using GPG
18
+    "npaste.encrypt": true,
19
+
20
+//  Encryption key length
21
+    "npaste.encryption_key_length": 32
22
+}

Loading…
Cancel
Save