Installation:
- Copy both scripts to your scripts_dir.
- Add the following to config:
@bind E = spawn @scripts_dir/external_editor.sh
- chmod +x external_editor.sh
Usage:
- Select (click/use the linkfollower) an editable form, go to command mode and hit E
Bugs:
I am not sure, maybe it fails sometimes (he, how accurate)
It should be able to handle every char (tested the common german ones (öäüÖÄÜß).
But with some char combination it fails I think. Don't know why.
external_editor.sh:
#!/bin/bash
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the -Do What The Fuck You Want
# To Public License-, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.
. "$UZBL_UTIL_DIR"/editor.sh
element=`echo 'js document.activeElement.type' | socat -t 0 - unix-connect:"$UZBL_SOCKET" | grep -v EVENT`
[ "$element" != 'text' -a "$element" != 'textarea' ] && exit 0
value=`echo 'js document.activeElement.value' | socat -t 0 - unix-connect:"$UZBL_SOCKET" | grep -v EVENT`
tmp_file=`mktemp /tmp/uzbl_edit.XXXXX`
echo -n "$value" > "$tmp_file"
$UZBL_EDITOR $tmp_file
if [ "$value" != "$(< $tmp_file)" ]
then
echo "script @scripts_dir/base64.js" > "$UZBL_FIFO"
# in case that actelem.type has changed, we do this test
echo "js var actelem = document.activeElement; if(actelem.type == 'text' || actelem.type == 'textarea') {actelem.value = decode64('`base64 $tmp_file`')};" > "$UZBL_FIFO"
fi
rm -rf $tmp_file
base64.js:
/* * utf8 function is (c) by Webtoolkit.info (http://www.webtoolkit.info/javascript-base64.html) * base64 function is (c) by Ntt.CC (http://ntt.cc/2008/01/19/base64-encoder-decoder-with-javascript.html) * (both slightly modified) * */ var keyStr = "ABCDEFGHIJKLMNOP" + "QRSTUVWXYZabcdef" + "ghijklmnopqrstuv" + "wxyz0123456789+/" + "=" function decode64(input) { var output = ""; var chr1, chr2, chr3 = ""; var enc1, enc2, enc3, enc4 = ""; var i = 0; // remove all characters that are not A-Z, a-z, 0-9, +, /, or = var base64test = /[^A-Za-z0-9\+\/\=]/g; if (base64test.exec(input)) { return "Oh crap!"; } input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); do { enc1 = keyStr.indexOf(input.charAt(i++)); enc2 = keyStr.indexOf(input.charAt(i++)); enc3 = keyStr.indexOf(input.charAt(i++)); enc4 = keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } chr1 = chr2 = chr3 = ""; enc1 = enc2 = enc3 = enc4 = ""; } while (i < input.length); return unescape(utf_decode(output)); } function utf_decode(utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0; while ( i < utftext.length ) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i+1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return string; }