mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 12:17:58 +01:00
:! command, fixed statusbar height properly, system() now returns the stdout string
This commit is contained in:
2
NEWS
2
NEWS
@@ -2,6 +2,8 @@
|
||||
2007-xx-xx:
|
||||
* version 0.6
|
||||
* THIS VERSION ONLY WORKS WITH FIREFOX 3.0
|
||||
* :b2 now allowed, no space required before the 2 anymore
|
||||
* :! to run commands through system() (UNIX only)
|
||||
* separated search and Ex command history
|
||||
* merge the existing status bar with the standard FF status bar so that
|
||||
security information and extension buttons are included
|
||||
|
||||
@@ -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();
|
||||
@@ -1557,6 +1557,23 @@ function Commands() //{{{
|
||||
"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("<pre>" + output + "</pre>");
|
||||
else
|
||||
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!"
|
||||
}
|
||||
));
|
||||
//}}}
|
||||
} //}}}
|
||||
|
||||
|
||||
@@ -144,8 +144,10 @@ fieldset.paypal {
|
||||
color: HighlightText !important;
|
||||
}
|
||||
|
||||
statusbarpanel {
|
||||
/* fixes the min-height: 22px from firefox */
|
||||
#status-bar, statusbarpanel {
|
||||
-moz-appearance: none !important;
|
||||
min-height: 18px !important;
|
||||
border: none !important;
|
||||
}
|
||||
#vimperator-statusline {
|
||||
|
||||
@@ -124,6 +124,30 @@ const vimperator = (function() //{{{
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO: make secure
|
||||
// TODO: test if it actually works on windows
|
||||
function getTempFile()
|
||||
{
|
||||
var file = Components.classes["@mozilla.org/file/local;1"].
|
||||
createInstance(Components.interfaces.nsILocalFile);
|
||||
if (navigator.platform == "Win32")
|
||||
{
|
||||
var dir = environment_service.get("TMP") || environment_service.get("TEMP") || "C:\\";
|
||||
file.initWithPath(dir + "\\vimperator.tmp");
|
||||
}
|
||||
else
|
||||
{
|
||||
var dir = environment_service.get("TMP") || environment_service.get("TEMP") || "/tmp/";
|
||||
file.initWithPath(dir + "/vimperator.tmp");
|
||||
}
|
||||
file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0600);
|
||||
|
||||
if (file.exists())
|
||||
return file;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
@@ -506,22 +530,36 @@ const vimperator = (function() //{{{
|
||||
// when https://bugzilla.mozilla.org/show_bug.cgi?id=68702 is fixed
|
||||
// is fixed, should use that instead of a tmpfile
|
||||
// TODO: make it usable on windows
|
||||
// TODO: check for errors/insecurities
|
||||
system: function (str)
|
||||
// TODO: pass "input" as stdin
|
||||
// TODO: add shell/shellcmdflag options to replace "sh" and "-c"
|
||||
system: function (str, input)
|
||||
{
|
||||
var file = Components.classes["@mozilla.org/file/local;1"].
|
||||
createInstance(Components.interfaces.nsILocalFile);
|
||||
var dir = environment_service.get("TMP") || environment_service.get("TEMP") || "/tmp/";
|
||||
file.initWithPath(dir + "vimperator.tmp");
|
||||
file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0600);
|
||||
this.run("sh", ["-c", str + " > " + file.path], true);
|
||||
var fd = vimperator.fopen(file, "<");
|
||||
var fileout = getTempFile();
|
||||
if (!fileout)
|
||||
return "";
|
||||
|
||||
var filein = null;
|
||||
var command = str + " > \"" + fileout.path.replace('"', '\\"') + "\"";
|
||||
if (input)
|
||||
{
|
||||
filein = getTempFile();
|
||||
var fdin = vimperator.fopen(filein, ">");
|
||||
fdin.write(input);
|
||||
fdin.close();
|
||||
command += " < \"" + filein.path.replace('"', '\\"') + "\"";
|
||||
}
|
||||
|
||||
this.run("sh", ["-c", command], true);
|
||||
var fd = vimperator.fopen(fileout, "<");
|
||||
if (!fd)
|
||||
return null;
|
||||
|
||||
var s = fd.read();
|
||||
fd.close();
|
||||
file.remove(false);
|
||||
fileout.remove(false);
|
||||
if (filein)
|
||||
filein.remove(false);
|
||||
|
||||
return s;
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user