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:
|
2007-xx-xx:
|
||||||
* version 0.6
|
* version 0.6
|
||||||
* THIS VERSION ONLY WORKS WITH FIREFOX 3.0
|
* 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
|
* separated search and Ex command history
|
||||||
* merge the existing status bar with the standard FF status bar so that
|
* merge the existing status bar with the standard FF status bar so that
|
||||||
security information and extension buttons are included
|
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++)
|
for (var i = 0; i < specs.length; i++)
|
||||||
{
|
{
|
||||||
var match;
|
var match;
|
||||||
if (match = specs[i].match(/(\w+)\[(\w+)\]/))
|
if (match = specs[i].match(/(\w+|!)\[(\w+)\]/))
|
||||||
{
|
{
|
||||||
short_names.push(match[1]);
|
short_names.push(match[1]);
|
||||||
long_names.push(match[1] + match[2]);
|
long_names.push(match[1] + match[2]);
|
||||||
@@ -114,7 +114,7 @@ Command.prototype.hasName = function(name)
|
|||||||
{
|
{
|
||||||
if (this.specs[i] == name) // literal command name
|
if (this.specs[i] == name) // literal command name
|
||||||
return true;
|
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]))
|
if (matchAbbreviation(name, this.specs[i]))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ function Commands() //{{{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 0 - count, 1 - cmd, 2 - special, 3 - args, 4 - heredoc tag
|
// 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)
|
if (!matches)
|
||||||
return [null, null, null, null, null];
|
return [null, null, null, null, null];
|
||||||
matches.shift();
|
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."
|
"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;
|
color: HighlightText !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
statusbarpanel {
|
/* fixes the min-height: 22px from firefox */
|
||||||
|
#status-bar, statusbarpanel {
|
||||||
-moz-appearance: none !important;
|
-moz-appearance: none !important;
|
||||||
|
min-height: 18px !important;
|
||||||
border: none !important;
|
border: none !important;
|
||||||
}
|
}
|
||||||
#vimperator-statusline {
|
#vimperator-statusline {
|
||||||
|
|||||||
@@ -124,6 +124,30 @@ const vimperator = (function() //{{{
|
|||||||
return null;
|
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 //////////////////////////////////////////
|
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
@@ -506,22 +530,36 @@ const vimperator = (function() //{{{
|
|||||||
// when https://bugzilla.mozilla.org/show_bug.cgi?id=68702 is fixed
|
// when https://bugzilla.mozilla.org/show_bug.cgi?id=68702 is fixed
|
||||||
// is fixed, should use that instead of a tmpfile
|
// is fixed, should use that instead of a tmpfile
|
||||||
// TODO: make it usable on windows
|
// TODO: make it usable on windows
|
||||||
// TODO: check for errors/insecurities
|
// TODO: pass "input" as stdin
|
||||||
system: function (str)
|
// TODO: add shell/shellcmdflag options to replace "sh" and "-c"
|
||||||
|
system: function (str, input)
|
||||||
{
|
{
|
||||||
var file = Components.classes["@mozilla.org/file/local;1"].
|
var fileout = getTempFile();
|
||||||
createInstance(Components.interfaces.nsILocalFile);
|
if (!fileout)
|
||||||
var dir = environment_service.get("TMP") || environment_service.get("TEMP") || "/tmp/";
|
return "";
|
||||||
file.initWithPath(dir + "vimperator.tmp");
|
|
||||||
file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0600);
|
var filein = null;
|
||||||
this.run("sh", ["-c", str + " > " + file.path], true);
|
var command = str + " > \"" + fileout.path.replace('"', '\\"') + "\"";
|
||||||
var fd = vimperator.fopen(file, "<");
|
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)
|
if (!fd)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var s = fd.read();
|
var s = fd.read();
|
||||||
fd.close();
|
fd.close();
|
||||||
file.remove(false);
|
fileout.remove(false);
|
||||||
|
if (filein)
|
||||||
|
filein.remove(false);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user