1. Ruslan Osmanov
  2. chrome/bee

Commits

Ruslan Osmanov  committed 4a42531

Some more cleanup

  • Participants
  • Parent commits e9cd73c
  • Branches master

Comments (0)

Files changed (8)

File .gitignore

View file
 CVS
 tags
+.ropeproject*
 
 *.tgz
 *.in

File README.md

View file
 *Bee* (_Browser's external editor_) is a Google Chrome (Chromium) extension for
 editing form `textarea` fields with an external editor.
 
-# Installation
+# Requirements
 
-## Linux and OS X
+This extension relies on a _native messaging host_ written in Python 3. So
+you'll need Python 3 itself plus some extra steps described in the following
+section.
 
-This extension requires an extra step to setup a _native messaging host_.
+# Installation
 
-- Download and uncompress [the latest version](https://bitbucket.org/osmanov/chrome-bee/get/master.tar.gz).
-- Launch `host/setup.sh` script with root privileges.
+## Linux and OS X
 
-One way to do that in terminal:
+- Run the following commands in a terminal:
 
+	:::bash
 	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
+	sudo ./host/install.sh
 
-The rest is just as simple as installing any other Chrome extension.
+- Download latest `.crx` file from the [downloads](https://bitbucket.org/osmanov/chrome-bee/downloads) page.
+- Open folder with the downloaded file in a graphical file manager
+- Open <chrome://extensions> tab in your browser
+- Drag-and-drop the `.crx` file onto the <chrome://extensions> tab
+- Chrome will ask for some confirmations. Give your approval, and you're done.
 
 ## Windows
 

File host/beectl

View file
-beectl.py

File host/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 conf and '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
 	"path": "/opt/osmanov/chrome/beectl",
 	"type": "stdio",
 	"allowed_origins": [
-		"chrome-extension://dbaifkpgelpeecacambibmaochndgooj/"
+		"chrome-extension://haenebhcepllcpneciadjchacagagfkc/"
 	]
 }

File host/install.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
+dir=$(dirname "$0")
+host_dir='/opt/osmanov/chrome/'
+host_name=com.ruslan_osmanov.bee
+host_file=beectl
+
+install -D -m 0644 "${dir}/${host_name}.json" "${manifest_dir}/${host_name}.json"
+install -D -m 0755 "${dir}/${host_file}" "${host_dir}/${host_file}"
+
+echo "Native messaging host ${host_name} has been installed into $host_dir."

File host/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}/host/${host_name}.json" "${manifest_dir}/${host_name}.json"
-install -D -m 0755 "${PWD}/host/${host_file}" "${host_dir}/${host_file}"
-
-echo "Native messaging host ${host_name} has been installed into $host_dir."

File package.sh

View file
+#!/bin/bash -
+
+dir=$(cd $(dirname "$0"); pwd)
+build_dir=$(dirname "$dir")/build
+paths=('google-chrome' 'chromium-browser' 'chromium')
+
+if [[ $# > 1 ]]; then
+	version=
+else
+	version="$1"
+fi
+crx="${build_dir}/bee-${version}.crx"
+
+for e in $paths
+do
+	exe=$(command -v $e)
+
+	[ -z "$exe" ] && continue
+done
+
+if [ -z "$exe" ]
+then
+	echo >&2 "Chrome executable not found"
+	exit 1
+fi
+
+$exe --pack-extension="${dir}" --pack-extension-key="${build_dir}/bee.pem" > /dev/null
+
+mv "${dir}/../bee.crx" "${crx}" && echo \
+	"Extension has been moved to ${crx}"