mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 00:17:58 +01:00
merge :! es command
This commit is contained in:
2
NEWS
2
NEWS
@@ -9,6 +9,8 @@
|
||||
(change with userChrome.css if you don't like it until we have :colorscheme)
|
||||
* :let mapleader="," and <Leader> in :map support
|
||||
* added new :let and :unlet commands
|
||||
* :b2 now allowed, no space required before the 2 anymore
|
||||
* :! to run commands through system()
|
||||
* separated search and Ex command history
|
||||
* added 'visualbellstyle' for styling/hiding the visual bell
|
||||
* merge the existing status bar with the standard FF status bar so that
|
||||
|
||||
@@ -42,7 +42,7 @@ function Command(specs, action, extra_info) //{{{
|
||||
for (var i = 0; i < specs.length; i++)
|
||||
{
|
||||
var match;
|
||||
if (match = specs[i].match(/(\w+)\[(\w+)\]/))
|
||||
if (match = specs[i].match(/(\w+|!)\[(\w+)\]/))
|
||||
{
|
||||
short_names.push(match[1]);
|
||||
long_names.push(match[1] + match[2]);
|
||||
@@ -114,7 +114,7 @@ Command.prototype.hasName = function(name)
|
||||
{
|
||||
if (this.specs[i] == name) // literal command name
|
||||
return true;
|
||||
else if (this.specs[i].match(/^\w+\[\w+\]$/)) // abbreviation spec
|
||||
else if (this.specs[i].match(/^(\w+|!)\[\w+\]$/)) // abbreviation spec
|
||||
if (matchAbbreviation(name, this.specs[i]))
|
||||
return true;
|
||||
}
|
||||
@@ -194,7 +194,7 @@ function Commands() //{{{
|
||||
}
|
||||
|
||||
// 0 - count, 1 - cmd, 2 - special, 3 - args, 4 - heredoc tag
|
||||
var matches = string.match(/^:*(\d+)?([a-zA-Z]+)(!)?(?:\s+(.*?)\s*)?$/);
|
||||
var matches = string.match(/^:*(\d+)?([a-zA-Z]+|!)(!)?(?:\s*(.*?)\s*)?$/);
|
||||
if (!matches)
|
||||
return [null, null, null, null, null];
|
||||
matches.shift();
|
||||
@@ -1629,6 +1629,31 @@ function Commands() //{{{
|
||||
short_help: "Set zoom value of the web page",
|
||||
help: "If <code class=\"argument\">{value}</code> can be an absolute value between 1 and 2000% or a relative value if prefixed with - or +. " +
|
||||
"If <code class=\"argument\">{value}</code> is omitted, zoom is reset to 100%."
|
||||
},
|
||||
{
|
||||
usage: ["zo[om][!] [value]", "zo[om][!] +{value} | -{value}"],
|
||||
short_help: "Set zoom value of current web page",
|
||||
help: "If <code class=\"argument\">{value}</code> can be an absolute value between 1 and 2000% or a relative value if prefixed with - or +. " +
|
||||
"If <code class=\"argument\">{value}</code> is omitted, zoom is reset to 100%.<br/>" +
|
||||
"Normally this command operates on the text zoom, if used with <code class=\"argument\">[!]</code> it operates on full zoom."
|
||||
}
|
||||
));
|
||||
addDefaultCommand(new Command(["!", "run"],
|
||||
function(args, special)
|
||||
{
|
||||
// TODO: if special, run the last command
|
||||
var output = vimperator.system(args)
|
||||
if (typeof output === "string")
|
||||
vimperator.echo(vimperator.util.escapeHTML(output));
|
||||
else
|
||||
// FIXME: why are we accepting only a string return value from v.system()? -- djk
|
||||
vimperator.echoerr("Invalid system command: " + args);
|
||||
},
|
||||
{
|
||||
usage: ["!{command}"],
|
||||
short_help: "Run a command",
|
||||
help: "Runs {command} through system() and displays its output. " +
|
||||
"Input redirection (< foo) not done, do not run commands which require stdin or it will hang Firefox!"
|
||||
}
|
||||
));
|
||||
//}}}
|
||||
|
||||
@@ -629,6 +629,89 @@ const vimperator = (function() //{{{
|
||||
.quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);
|
||||
},
|
||||
|
||||
run: function(program, args, blocking)
|
||||
{
|
||||
const WINDOWS = navigator.platform == "Win32";
|
||||
|
||||
var file = Components.classes["@mozilla.org/file/local;1"].
|
||||
createInstance(Components.interfaces.nsILocalFile);
|
||||
try
|
||||
{
|
||||
file.initWithPath(program);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
var dirs = environment_service.get("PATH").split(WINDOWS ? ";" : ":");
|
||||
for (var i = 0; i < dirs.length; i++)
|
||||
{
|
||||
var path = dirs[i] + (WINDOWS ? "\\" : "/") + program;
|
||||
try
|
||||
{
|
||||
file.initWithPath(path);
|
||||
if (file.exists())
|
||||
break;
|
||||
}
|
||||
catch (e) { }
|
||||
}
|
||||
}
|
||||
if (!file.exists())
|
||||
{
|
||||
vimperator.echoerr("command not found: " + program);
|
||||
return -1;
|
||||
}
|
||||
|
||||
var process = Components.classes["@mozilla.org/process/util;1"].
|
||||
createInstance(Components.interfaces.nsIProcess);
|
||||
process.init(file);
|
||||
|
||||
var ec = process.run(blocking, args, args.length);
|
||||
return ec;
|
||||
},
|
||||
|
||||
// when https://bugzilla.mozilla.org/show_bug.cgi?id=68702 is fixed
|
||||
// is fixed, should use that instead of a tmpfile
|
||||
// TODO: pass "input" as stdin
|
||||
// TODO: add shell/shellcmdflag options to replace "sh" and "-c"
|
||||
system: function (str, input)
|
||||
{
|
||||
const WINDOWS = navigator.platform == "Win32"; // FIXME: duplicated everywhere
|
||||
|
||||
var fileout = getTempFile();
|
||||
if (!fileout)
|
||||
return "";
|
||||
|
||||
if (WINDOWS)
|
||||
var command = str + " > " + fileout.path;
|
||||
else
|
||||
var command = str + " > \"" + fileout.path.replace('"', '\\"') + "\"";
|
||||
|
||||
var filein = null;
|
||||
if (input)
|
||||
{
|
||||
filein = getTempFile();
|
||||
var fdin = vimperator.fopen(filein, ">");
|
||||
fdin.write(input);
|
||||
fdin.close();
|
||||
command += " < \"" + filein.path.replace('"', '\\"') + "\"";
|
||||
}
|
||||
|
||||
if (WINDOWS)
|
||||
this.run("cmd.exe", ["/C", command], true);
|
||||
else
|
||||
this.run("sh", ["-c", command], true);
|
||||
|
||||
var fd = vimperator.fopen(fileout, "<");
|
||||
if (!fd)
|
||||
return null;
|
||||
|
||||
var s = fd.read();
|
||||
fd.close();
|
||||
fileout.remove(false);
|
||||
if (filein)
|
||||
filein.remove(false);
|
||||
|
||||
return s;
|
||||
},
|
||||
|
||||
// files which end in .js are sourced as pure javascript files,
|
||||
// no need (actually forbidden) to add: js <<EOF ... EOF around those files
|
||||
@@ -820,7 +903,19 @@ const vimperator = (function() //{{{
|
||||
vimperator.events.destroy();
|
||||
|
||||
window.dump("All vimperator modules destroyed\n");
|
||||
},
|
||||
|
||||
sleep: function(ms)
|
||||
{
|
||||
var threadManager = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
|
||||
var mainThread = threadManager.mainThread;
|
||||
|
||||
var then = new Date().getTime(), now = then;
|
||||
for (; now - then < ms; now = new Date().getTime()) {
|
||||
mainThread.processNextEvent(true);
|
||||
}
|
||||
}
|
||||
|
||||
} //}}}
|
||||
})(); //}}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user