1. Ruslan Osmanov
  2. chrome/bee

Commits

Ruslan Osmanov  committed a5ab109

Some cleanup

  • Participants
  • Parent commits 9f92ce8
  • Branches master

Comments (0)

Files changed (10)

File README.md

View file
 # About
 
-*Bee* is a Google Chrome (Chromium) extension for editing form fields with an external editor.
+*Bee* (_Browser's external editor_) is a Google Chrome (Chromium) extension for
+editing form `textarea` fields with an external editor.
+
+# Installation
+
+## Linux and OS X
+
+This extension requires an extra step to setup a _native messaging host_.
+
+- Download and uncompress [the latest version](https://bitbucket.org/osmanov/chrome-bee/get/master.tar.gz).
+- Launch `host/setup.sh` script with root privileges.
+
+One way to do that in terminal:
+
+	d=/tmp/chrome-bee
+	mkdir -p $d
+	cd $d
+	wget -q -O - https://bitbucket.org/osmanov/chrome-bee/get/master.tar.gz | tar -xzf - --strip-components 1
+	sudo ./host/setup.sh
+
+The rest is just as simple as installing any other Chrome extension.
+
+## Windows
+
+Currently Windows is not supported. Pull requests are welcome though.
 
 # License
 

File TODO.md

View file
+- [native client](https://developers.google.com/native-client/dev/)
+

File host/beectl

View file
+beectl.py

File host/beectl.py

View file
+#!/usr/bin/env python3
+#
+# Google Chrome (Chromium) browser's Bee extension native messaging host.
+#
+# User can specify path to desired external editor in ~/.config/beectl.conf
+# file, e.g.:
+#
+#   bee_editor = /usr/bin/gedit
+#
+# Otherwise the script tries to guess editor by iterating over list of popular
+# editors, such as gvim, macvim, qvim, gedit, kate, emacs etc.; then falls back
+# to $EDITOR environment variable.
+#
+# When editor's subprocess is finished, the script bypasses the new text back
+# to the textarea control.
+#
+# Copyright © 2014 Ruslan Osmanov <rrosmanov at gmail dot com>
+
+import json
+import struct
+import re
+import os.path
+import sys
+import tempfile
+import subprocess
+
+
+def which(exe):
+    for dir in os.environ['PATH'].split(':'):
+        path = os.path.join(dir, exe)
+        if os.path.exists(path):
+            return path
+    return False
+
+
+def parse_user_config():
+    filename = os.path.expanduser("~/.config/beectl.conf")
+    if (not os.path.exists(filename)):
+        return None
+
+    conf = {}
+    with open(filename) as fp:
+        for line in iter(fp.readline, ''):
+            c = re.split('[\s\=]+', line, 1)
+            conf[c[0]] = c[1]
+
+    return conf
+
+
+def get_editor(conf):
+    if 'bee_editor' in conf:
+        return conf['bee_editor']
+
+    for e in ['gedit', 'kate', 'sublime', 'gvim',
+              'qvim', 'macvim', 'emacs', 'leafpad']:
+        path = which(e)
+        if which(e):
+            return path
+
+    return os.getenv('EDITOR')
+
+
+def main():
+    conf = parse_user_config()
+    bee_editor = get_editor(conf)
+
+    if not bee_editor:
+        sys.exit("No editor found")
+
+    args = re.split('\s+', bee_editor)
+
+    # no-fork option for vim family
+    if re.match('.*vim', bee_editor):
+        args.append('-f')
+
+    # 1st 4 bytes is the message type
+    text_len_bytes = sys.stdin.buffer.read(4)
+
+    if len(text_len_bytes) == 0:
+        sys.exit(0)
+
+    text_len = struct.unpack('I', text_len_bytes)[0]
+
+    json_text = sys.stdin.buffer.read(text_len)
+    text = json.loads(json_text.decode('UTF-8'))
+
+    f = tempfile.mkstemp('', 'chrome_bee_')
+    os.write(f[0], bytes(text['text'], 'UTF-8'))
+    args.append(f[1])
+
+    subprocess.call(args);
+    text = ""
+    os.lseek(f[0], 0, os.SEEK_SET)
+    while True:
+        r = os.read(f[0], 1024)
+        if not r:
+            break
+        text += r.decode('UTF-8');
+    os.close(f[0])
+    os.unlink(f[1])
+
+    # Write message size
+    response = json.dumps({"text": text}
+    sys.stdout.buffer.write(struct.pack('I', len(response)))
+    # Write message itself
+    sys.stdout.write(response)
+    sys.stdout.flush()
+
+    sys.exit(0)
+
+
+if __name__ == '__main__':
+    main()

File host/com.ruslan_osmanov.bee.json

View file
+{
+	"name": "com.ruslan_osmanov.bee",
+	"description": "Bee - Browser's external editor",
+	"path": "/opt/osmanov/chrome/beectl",
+	"type": "stdio",
+	"allowed_origins": [
+		"chrome-extension://dbaifkpgelpeecacambibmaochndgooj/"
+	]
+}

File host/setup.sh

View file
+#!/bin/bash -
+# vim: noet ts=4 sts=4 sw=4
+#
+# Native messaging host setup.
+# Requires root privileges
+#
+# Copyright © 2014 Ruslan Osmanov <rrosmanov@gmail.com>
+
+if [ $(uname -s) == 'Darwin' ]
+then
+	manifest_dir='/Library/Google/Chrome/NativeMessagingHosts'
+else
+	manifest_dir='/etc/opt/chrome/native-messaging-hosts'
+fi
+host_dir='/opt/osmanov/chrome/'
+host_name=com.ruslan_osmanov.bee
+host_file=beectl
+
+install -D -m 0644 "${PWD}/server/${host_name}.json" "${manifest_dir}/${host_name}.json"
+install -D -m 0755 "${PWD}/server/${host_file}" "${host_dir}/${host_file}"
+
+echo "Native messaging host ${host_name} has been installed into $host_dir."

File server/beectl

-beectl.py

File server/beectl.py

-#!/usr/bin/env python3
-#
-# Google Chrome (Chromium) browser's Bee extension native messaging host.
-#
-# User can specify path to desired external editor in ~/.config/beectl.conf
-# file, e.g.:
-#
-#   bee_editor = /usr/bin/gedit
-#
-# Otherwise the script tries to guess editor by iterating over list of popular
-# editors, such as gvim, macvim, qvim, gedit, kate, emacs etc.; then falls back
-# to $EDITOR environment variable.
-#
-# When editor's subprocess is finished, the script bypasses the new text back
-# to the textarea control.
-#
-# Copyright © 2014 Ruslan Osmanov <rrosmanov at gmail dot com>
-
-import json
-import struct
-import re
-import os.path
-import sys
-import tempfile
-import subprocess
-
-
-def which(exe):
-    for dir in os.environ['PATH'].split(':'):
-        path = os.path.join(dir, exe)
-        if os.path.exists(path):
-            return path
-    return False
-
-
-def parse_user_config():
-    filename = os.path.expanduser("~/.config/beectl.conf")
-    if (not os.path.exists(filename)):
-        return None
-
-    conf = {}
-    with open(filename) as fp:
-        for line in iter(fp.readline, ''):
-            c = re.split('[\s\=]+', line, 1)
-            conf[c[0]] = c[1]
-
-    return conf
-
-
-def get_editor(conf):
-    if 'bee_editor' in conf:
-        return conf['bee_editor']
-
-    for e in ['gedit', 'kate', 'sublime', 'gvim',
-              'qvim', 'macvim', 'emacs', 'leafpad']:
-        path = which(e)
-        if which(e):
-            return path
-
-    return os.getenv('EDITOR')
-
-
-def main():
-    conf = parse_user_config()
-    bee_editor = get_editor(conf)
-
-    if not bee_editor:
-        sys.exit("No editor found")
-
-    args = re.split('\s+', bee_editor)
-
-    # no-fork option for vim family
-    if re.match('.*vim', bee_editor):
-        args.append('-f')
-
-    # 1st 4 bytes is the message type
-    text_len_bytes = sys.stdin.buffer.read(4)
-
-    if len(text_len_bytes) == 0:
-        sys.exit(0)
-
-    text_len = struct.unpack('I', text_len_bytes)[0]
-
-    json_text = sys.stdin.buffer.read(text_len)
-    text = json.loads(json_text.decode('UTF-8'))
-
-    f = tempfile.mkstemp('', 'chrome_bee_')
-    os.write(f[0], bytes(text['text'], 'UTF-8'))
-    args.append(f[1])
-
-    subprocess.call(args);
-    text = ""
-    os.lseek(f[0], 0, os.SEEK_SET)
-    while True:
-        r = os.read(f[0], 1024)
-        if not r:
-            break
-        text += r.decode('UTF-8');
-    os.close(f[0])
-    os.unlink(f[1])
-
-    # Write message size
-    response = json.dumps({"text": text}
-    sys.stdout.buffer.write(struct.pack('I', len(response)))
-    # Write message itself
-    sys.stdout.write(response)
-    sys.stdout.flush()
-
-    sys.exit(0)
-
-
-if __name__ == '__main__':
-    main()

File server/com.ruslan_osmanov.bee.json

-{
-	"name": "com.ruslan_osmanov.bee",
-	"description": "Bee - Browser's external editor",
-	"path": "/opt/osmanov/chrome/beectl",
-	"type": "stdio",
-	"allowed_origins": [
-		"chrome-extension://dbaifkpgelpeecacambibmaochndgooj/"
-	]
-}

File server/setup.sh

-#!/bin/bash -
-# vim: noet ts=4 sts=4 sw=4
-#
-# Native messaging host setup.
-# Requires root privileges
-#
-# Copyright © 2014 Ruslan Osmanov <rrosmanov@gmail.com>
-
-if [ $(uname -s) == 'Darwin' ]
-then
-	manifest_dir='/Library/Google/Chrome/NativeMessagingHosts'
-else
-	manifest_dir='/etc/opt/chrome/native-messaging-hosts'
-fi
-host_dir='/opt/osmanov/chrome/'
-host_name=com.ruslan_osmanov.bee
-host_file=beectl
-
-install -D -m 0644 "${PWD}/server/${host_name}.json" "${manifest_dir}/${host_name}.json"
-install -D -m 0755 "${PWD}/server/${host_file}" "${host_dir}/${host_file}"
-
-echo "Native messaging host ${host_name} has been installed into $host_dir."