...
 
Commits (2)
define(["jquery", "emitter"], function($, Emitter) {
define(["jquery", "emitter", "vispa/utils"], function($, Emitter, Utils) {
var CodeEditorActions = Emitter._extend({
......@@ -87,6 +87,7 @@ define(["jquery", "emitter"], function($, Emitter) {
self.editor.path = path;
self.view.state.set("writable", self.view.state.get("writable") && res.writable, 1);
self.view.state.set("path", path);
self.parseShebang(res.content);
self.mtime = res.mtime;
self.editor.setContent(res.content);
if (!reset)
......@@ -143,6 +144,19 @@ define(["jquery", "emitter"], function($, Emitter) {
return this;
},
parseShebang: function(content) {
var shebang = content.match(/^#! ?(\S+) *(.*)/);
if (!shebang) return;
var command = Utils.singleQuote(shebang[2], /\s/);
if (shebang[1] == "/usr/bin/env") {
if (shebang[2].startsWith("-S"))
command = shebang[2].replace(/^-S\s+/, "");
} else
command = Utils.singleQuote(shebang[1], /\s/) + " " + command;
command += " '%file'"
this.view.state.set("command", command);
},
setupAutoSave: function() {
var self = this;
......
......@@ -59,7 +59,7 @@ import re
import shutil
import stat
import subprocess
import fsmonitor
from fsmonitor.polling import FSMonitor
import vispa
import tempfile
from pwd import getpwall
......@@ -790,7 +790,7 @@ class WatchService(object):
self.subscribers = {}
self.watches = {}
self.lock = Lock()
self.monitor = fsmonitor.FSMonitor()
self.monitor = FSMonitor()
self.run = True
self.thread = Thread(target=self._worker)
self.thread.daemon = True
......
......@@ -282,6 +282,25 @@ define(["require"], function(require) {
replace(/\/+/g, "/").
replace(/\/\.(?=\/|$)/g, "").
replace(/\/[^\/]+\/\.\.(?=\/|$)/g, "");
},
/** indent: 1
* .. js:function:: singleQuote(string[, trigger])
*
* :param String string: The string to quote.
* :param String|RexEx trigger: The trigger for quoting to *search* for in *string*. The
* default will match anything.
*
* :return: The cleaned path.
* :rtype: String
*/
singleQuote: function (string, trigger) {
if (trigger === undefined)
trigger = /^/;
if (~string.search(trigger))
return "'" + string.replace(/'/g, "'\"'\"'") + "'";
else
return string;
}
};
......