1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 05:38:01 +01:00

Added :write !cmd and :write >>file.

This commit is contained in:
Kris Maglione
2010-10-04 19:36:19 -04:00
parent 9b3e28cb42
commit a21c2510e3
4 changed files with 57 additions and 7 deletions

View File

@@ -976,9 +976,11 @@ const Buffer = Module("buffer", {
*/ */
viewSourceExternally: Class("viewSourceExternally", viewSourceExternally: Class("viewSourceExternally",
XPCOM([Ci.nsIWebProgressListener, Ci.nsISupportsWeakReference]), { XPCOM([Ci.nsIWebProgressListener, Ci.nsISupportsWeakReference]), {
init: function (doc) { init: function (doc, callback) {
let url = isString(doc) ? doc : doc.location.href; let url = isString(doc) ? doc : doc.location.href;
let charset = isString(doc) ? null : doc.characterSet; let charset = isString(doc) ? null : doc.characterSet;
this.callback = callback ||
function (file) editor.editFileExternally(file.path);
let webNav = window.getWebNavigation(); let webNav = window.getWebNavigation();
try { try {
@@ -994,7 +996,7 @@ const Buffer = Module("buffer", {
let uri = util.newURI(url, charset); let uri = util.newURI(url, charset);
if (uri.scheme == "file") if (uri.scheme == "file")
editor.editFileExternally(uri.QueryInterface(Ci.nsIFileURL).file.path); this.callback(File(uri.QueryInterface(Ci.nsIFileURL).file));
else { else {
if (descriptor) { if (descriptor) {
// we'll use nsIWebPageDescriptor to get the source because it may // we'll use nsIWebPageDescriptor to get the source because it may
@@ -1035,7 +1037,7 @@ const Buffer = Module("buffer", {
this.file = io.createTempFile(); this.file = io.createTempFile();
this.file.write(this.docShell.document.body.textContent); this.file.write(this.docShell.document.body.textContent);
} }
editor.editFileExternally(this.file.path); this.callback(this.file);
this.file.remove(false); this.file.remove(false);
} }
finally { finally {
@@ -1318,7 +1320,25 @@ const Buffer = Module("buffer", {
let chosenData = null; let chosenData = null;
let filename = args[0]; let filename = args[0];
let command = commandline.command;
if (filename) { if (filename) {
if (filename[0] == "!")
return buffer.viewSourceExternally(buffer.focusedFrame.document,
function (file) {
let output = io.system(filename.substr(1), file);
commandline.command = command;
commandline.commandOutput(<span highlight="CmdOutput">{output}</span>);
});
if (/^>>/.test(filename)) {
let file = io.File(filename.replace(/^>>\s*/, ""));
dactyl.assert(file.exists() && file.isWritable(), file.path.quote() + ": E212: Can't open file for writing");
return buffer.viewSourceExternally(buffer.focusedFrame.document,
function (tmpFile) {
file.write(tmpFile.read(), ">>");
});
}
let file = io.File(filename); let file = io.File(filename);
dactyl.assert(!file.exists() || args.bang, dactyl.assert(!file.exists() || args.bang,
@@ -1347,7 +1367,14 @@ const Buffer = Module("buffer", {
{ {
argCount: "?", argCount: "?",
bang: true, bang: true,
completer: function (context) completion.file(context) completer: function (context) {
if (context.filter[0] == "!")
return;
if (/^>>/.test(context.filter))
context.advance(/^>>\s*/.exec(context.filter)[0].length);
return completion.file(context)
},
literal: 0
}); });
commands.add(["st[op]"], commands.add(["st[op]"],

View File

@@ -433,7 +433,9 @@ lookup:
function escape(str) '"' + str.replace(/[\\"$]/g, "\\$&") + '"'; function escape(str) '"' + str.replace(/[\\"$]/g, "\\$&") + '"';
return this.withTempFiles(function (stdin, stdout, cmd) { return this.withTempFiles(function (stdin, stdout, cmd) {
if (input) if (input instanceof File)
stdin = input;
else if (input)
stdin.write(input); stdin.write(input);
// TODO: implement 'shellredir' // TODO: implement 'shellredir'

View File

@@ -415,6 +415,26 @@ want to bypass &dactyl.appName;'s key handling and pass keys directly to
</description> </description>
</item> </item>
<item>
<spec>:write >> <a>file</a></spec>
<description>
<p>
Appends the current web page to the file <a>file</a>. The given
file must already exist.
</p>
</description>
</item>
<item>
<spec>:write !<a>cmd</a></spec>
<description>
<p>
Writes the current web page to <a>cmd</a> and prints the command's
output.
</p>
</description>
</item>
<h2 tag="quitting save-session">Quitting</h2> <h2 tag="quitting save-session">Quitting</h2>
<item> <item>

View File

@@ -57,14 +57,15 @@
* Added 'banghist' option. * Added 'banghist' option.
* Added BookmarkChange, BookmarkRemove autocommands. * Added BookmarkChange, BookmarkRemove autocommands.
* Added -keyword, -tags, -title to :delbmarks. * Added -keyword, -tags, -title to :delbmarks.
* Added "passwords" and "venkman" dialogs to :dialog.
* Added 'hintkeys' option. * Added 'hintkeys' option.
* Added "transliterated" option to 'hintmatching'.
* Replaced 'focuscontent' with 'strictfocus'. * Replaced 'focuscontent' with 'strictfocus'.
* Added 'wildanchor' option. * Added 'wildanchor' option.
* Added "transliterated" option to 'hintmatching'.
* Added -javascript option to :abbrev and :map. * Added -javascript option to :abbrev and :map.
* Added several new options to :map. * Added several new options to :map.
* Added -agent flag to :style. * Added -agent flag to :style.
* Added "passwords" and "venkman" dialogs to :dialog. * Added :write !cmd and :write >>file
* Removed the :source line at the end of files generated by * Removed the :source line at the end of files generated by
:mkpentadactylrc. :mkpentadactylrc.
* gf now toggles between source and content view. * gf now toggles between source and content view.