mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 16:07:59 +01:00
Add a command-line handler to process the -liberator option.
This commit is contained in:
@@ -615,6 +615,25 @@ const liberator = (function () //{{{
|
|||||||
/** @property {string} The name of the current user profile. */
|
/** @property {string} The name of the current user profile. */
|
||||||
profileName: services.get("directory").get("ProfD", Ci.nsIFile).leafName.replace(/^.+?\./, ""),
|
profileName: services.get("directory").get("ProfD", Ci.nsIFile).leafName.replace(/^.+?\./, ""),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {Object} The map of command-line options. These are
|
||||||
|
* specified in the argument to the host application's -liberator
|
||||||
|
* option. E.g. $ firefox -liberator '+u=tempRcFile ++noplugin'
|
||||||
|
* Supported options:
|
||||||
|
* +u=RCFILE Use RCFILE instead of .vimperatorrc.
|
||||||
|
* ++noplugin Don't load plugins.
|
||||||
|
*/
|
||||||
|
commandLineOptions: {
|
||||||
|
/** @property Whether plugin loading should be prevented. */
|
||||||
|
noPlugins: false,
|
||||||
|
/** @property An RC file to use rather than the default. */
|
||||||
|
rcFile: null,
|
||||||
|
/** @property An Ex command to run before any initialization is performed. */
|
||||||
|
preCommand: null,
|
||||||
|
/** @property An Ex command to run after all initialization is performed. */
|
||||||
|
postCommand: null
|
||||||
|
},
|
||||||
|
|
||||||
// @param type can be:
|
// @param type can be:
|
||||||
// "submit": when the user pressed enter in the command line
|
// "submit": when the user pressed enter in the command line
|
||||||
// "change"
|
// "change"
|
||||||
@@ -1225,6 +1244,17 @@ const liberator = (function () //{{{
|
|||||||
services.get("appStartup").quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit);
|
services.get("appStartup").quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
parseCommandLine: function (commandline)
|
||||||
|
{
|
||||||
|
const options = [
|
||||||
|
[["+u"], commands.OPTIONS_STRING],
|
||||||
|
[["++noplugin"], commands.OPTIONS_NOARG],
|
||||||
|
[["++cmd"], commands.OPTIONS_STRING],
|
||||||
|
[["+c"], commands.OPTIONS_STRING]
|
||||||
|
];
|
||||||
|
return commands.parseArgs(commandline, options, "*");
|
||||||
|
},
|
||||||
|
|
||||||
// TODO: move to {muttator,vimperator,...}.js
|
// TODO: move to {muttator,vimperator,...}.js
|
||||||
// this function is called when the chrome is ready
|
// this function is called when the chrome is ready
|
||||||
startup: function ()
|
startup: function ()
|
||||||
@@ -1268,6 +1298,19 @@ const liberator = (function () //{{{
|
|||||||
|
|
||||||
liberator.log("All modules loaded", 3);
|
liberator.log("All modules loaded", 3);
|
||||||
|
|
||||||
|
let commandline = services.get("commandLineHandler").wrappedJSObject.optionValue;
|
||||||
|
if (commandline)
|
||||||
|
{
|
||||||
|
let args = liberator.parseCommandLine(commandline);
|
||||||
|
liberator.commandLineOptions.rcFile = args["+u"];
|
||||||
|
liberator.commandLineOptions.noPlugins = "++noplugin" in args;
|
||||||
|
liberator.commandLineOptions.postCommand = args["+c"];
|
||||||
|
liberator.commandLineOptions.preCommand = args["++cmd"];
|
||||||
|
liberator.dump("Processing command-line option: " + commandline);
|
||||||
|
}
|
||||||
|
|
||||||
|
liberator.log("Command-line options: " + util.objectToString(liberator.commandLineOptions), 3);
|
||||||
|
|
||||||
// first time intro message
|
// first time intro message
|
||||||
const firstTime = "extensions." + config.name.toLowerCase() + ".firsttime";
|
const firstTime = "extensions." + config.name.toLowerCase() + ".firsttime";
|
||||||
if (options.getPref(firstTime, true))
|
if (options.getPref(firstTime, true))
|
||||||
@@ -1284,6 +1327,9 @@ const liberator = (function () //{{{
|
|||||||
// TODO: we should have some class where all this guioptions stuff fits well
|
// TODO: we should have some class where all this guioptions stuff fits well
|
||||||
hideGUI();
|
hideGUI();
|
||||||
|
|
||||||
|
if (liberator.commandLineOptions.preCommand)
|
||||||
|
liberator.execute(liberator.commandLineOptions.preCommand);
|
||||||
|
|
||||||
// finally, read the RC file and source plugins
|
// finally, read the RC file and source plugins
|
||||||
// make sourcing asynchronous, otherwise commands that open new tabs won't work
|
// make sourcing asynchronous, otherwise commands that open new tabs won't work
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
@@ -1292,25 +1338,37 @@ const liberator = (function () //{{{
|
|||||||
let init = services.get("environment").get(extensionName + "_INIT");
|
let init = services.get("environment").get(extensionName + "_INIT");
|
||||||
let rcFile = io.getRCFile("~");
|
let rcFile = io.getRCFile("~");
|
||||||
|
|
||||||
if (init)
|
if (liberator.commandLineOptions.rcFile)
|
||||||
liberator.execute(init);
|
{
|
||||||
|
let filename = liberator.commandLineOptions.rcFile;
|
||||||
|
if (!/^(NONE|NORC)$/.test(filename))
|
||||||
|
io.source(io.getFile(filename).path, false); // let io.source handle any read failure like Vim
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (rcFile)
|
if (init)
|
||||||
{
|
liberator.execute(init);
|
||||||
io.source(rcFile.path, true);
|
|
||||||
services.get("environment").set("MY_" + extensionName + "RC", rcFile.path);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
liberator.log("No user RC file found", 3);
|
{
|
||||||
|
if (rcFile)
|
||||||
|
{
|
||||||
|
io.source(rcFile.path, true);
|
||||||
|
services.get("environment").set("MY_" + extensionName + "RC", rcFile.path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
liberator.log("No user RC file found", 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options["exrc"] && !liberator.commandLineOptions.rcFile)
|
||||||
|
{
|
||||||
|
let localRCFile = io.getRCFile(io.getCurrentDirectory().path);
|
||||||
|
if (localRCFile && !localRCFile.equals(rcFile))
|
||||||
|
io.source(localRCFile.path, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options["exrc"])
|
if (liberator.commandLineOptions.rcFile == "NONE" || liberator.commandLineOptions.noPlugins)
|
||||||
{
|
options["loadplugins"] = false;
|
||||||
let localRCFile = io.getRCFile(io.getCurrentDirectory().path);
|
|
||||||
if (localRCFile && !localRCFile.equals(rcFile))
|
|
||||||
io.source(localRCFile.path, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options["loadplugins"])
|
if (options["loadplugins"])
|
||||||
liberator.loadPlugins();
|
liberator.loadPlugins();
|
||||||
@@ -1327,6 +1385,9 @@ const liberator = (function () //{{{
|
|||||||
option.value = option.value;
|
option.value = option.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (liberator.commandLineOptions.postCommand)
|
||||||
|
liberator.execute(liberator.commandLineOptions.postCommand);
|
||||||
|
|
||||||
liberator.triggerObserver("enter", null);
|
liberator.triggerObserver("enter", null);
|
||||||
autocommands.trigger(config.name + "Enter", {});
|
autocommands.trigger(config.name + "Enter", {});
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ function Services()
|
|||||||
//self.add("autoCompleteSearch", "@mozilla.org/autocomplete/search;1?name=songbird-autocomplete", Ci.nsIAutoCompleteSearch);
|
//self.add("autoCompleteSearch", "@mozilla.org/autocomplete/search;1?name=songbird-autocomplete", Ci.nsIAutoCompleteSearch);
|
||||||
self.add("browserSearch", "@mozilla.org/browser/search-service;1", Ci.nsIBrowserSearchService);
|
self.add("browserSearch", "@mozilla.org/browser/search-service;1", Ci.nsIBrowserSearchService);
|
||||||
self.add("cache", "@mozilla.org/network/cache-service;1", Ci.nsICacheService);
|
self.add("cache", "@mozilla.org/network/cache-service;1", Ci.nsICacheService);
|
||||||
|
self.add("commandLineHandler", "@mozilla.org/commandlinehandler/general-startup;1?type=liberator", Ci.nsICommandLineHandler);
|
||||||
self.add("console", "@mozilla.org/consoleservice;1", Ci.nsIConsoleService);
|
self.add("console", "@mozilla.org/consoleservice;1", Ci.nsIConsoleService);
|
||||||
self.add("directory", "@mozilla.org/file/directory_service;1", Ci.nsIProperties);
|
self.add("directory", "@mozilla.org/file/directory_service;1", Ci.nsIProperties);
|
||||||
self.add("environment", "@mozilla.org/process/environment;1", Ci.nsIEnvironment);
|
self.add("environment", "@mozilla.org/process/environment;1", Ci.nsIEnvironment);
|
||||||
|
|||||||
39
muttator/components/commandline-handler.js
Normal file
39
muttator/components/commandline-handler.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
|
|
||||||
|
function CommandLineHandler()
|
||||||
|
{
|
||||||
|
this.wrappedJSObject = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandLineHandler.prototype = {
|
||||||
|
|
||||||
|
classDescription: "Liberator Command-line Handler",
|
||||||
|
|
||||||
|
classID: Components.ID("{16dc34f7-6d22-4aa4-a67f-2921fb5dcb69}"),
|
||||||
|
|
||||||
|
contractID: "@mozilla.org/commandlinehandler/general-startup;1?type=liberator",
|
||||||
|
|
||||||
|
_xpcom_categories: [{
|
||||||
|
category: "command-line-handler",
|
||||||
|
entry: "m-liberator"
|
||||||
|
}],
|
||||||
|
|
||||||
|
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsICommandLineHandler]),
|
||||||
|
|
||||||
|
handle: function (commandLine)
|
||||||
|
{
|
||||||
|
// TODO: handle remote launches differently?
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.optionValue = commandLine.handleFlagWithParam("liberator", false);
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
//"liberator: option -liberator requires an argument"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function NSGetModule(compMgr, fileSpec) XPCOMUtils.generateModule([CommandLineHandler]);
|
||||||
|
|
||||||
|
// vim: set fdm=marker sw=4 ts=4 et:
|
||||||
@@ -7,6 +7,8 @@
|
|||||||
* add \ mapping - toggle between rendered and source view
|
* add \ mapping - toggle between rendered and source view
|
||||||
* add ;c extended hint mode - open the context menu
|
* add ;c extended hint mode - open the context menu
|
||||||
* :help all now shows all help sections in a single page
|
* :help all now shows all help sections in a single page
|
||||||
|
* command-line options are now supported via the host application's
|
||||||
|
-liberator option
|
||||||
|
|
||||||
2009-05-21:
|
2009-05-21:
|
||||||
* version 2.1
|
* version 2.1
|
||||||
|
|||||||
39
vimperator/components/commandline-handler.js
Normal file
39
vimperator/components/commandline-handler.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
|
|
||||||
|
function CommandLineHandler()
|
||||||
|
{
|
||||||
|
this.wrappedJSObject = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandLineHandler.prototype = {
|
||||||
|
|
||||||
|
classDescription: "Liberator Command-line Handler",
|
||||||
|
|
||||||
|
classID: Components.ID("{16dc34f7-6d22-4aa4-a67f-2921fb5dcb69}"),
|
||||||
|
|
||||||
|
contractID: "@mozilla.org/commandlinehandler/general-startup;1?type=liberator",
|
||||||
|
|
||||||
|
_xpcom_categories: [{
|
||||||
|
category: "command-line-handler",
|
||||||
|
entry: "m-liberator"
|
||||||
|
}],
|
||||||
|
|
||||||
|
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsICommandLineHandler]),
|
||||||
|
|
||||||
|
handle: function (commandLine)
|
||||||
|
{
|
||||||
|
// TODO: handle remote launches differently?
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.optionValue = commandLine.handleFlagWithParam("liberator", false);
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
//"liberator: option -liberator requires an argument"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function NSGetModule(compMgr, fileSpec) XPCOMUtils.generateModule([CommandLineHandler]);
|
||||||
|
|
||||||
|
// vim: set fdm=marker sw=4 ts=4 et:
|
||||||
@@ -1,7 +1,43 @@
|
|||||||
heading:Starting{nbsp}Vimperator[starting]
|
heading:Starting{nbsp}Vimperator[starting]
|
||||||
|
|
||||||
Vimperator does not yet read any command-line options. When it does, they will
|
|startup-options| +
|
||||||
be documented here.
|
|
||||||
|
Command-line options can be passed to Vimperator via the -liberator Firefox
|
||||||
|
option. These are passed as single string argument.
|
||||||
|
E.g firefox -liberator "\++cmd=\'set exrc' +u=\'tempRcFile' \++noplugin"
|
||||||
|
|
||||||
|
|+c| +
|
||||||
|
||+c={command}||
|
||||||
|
________________________________________________________________________________
|
||||||
|
Execute a single Ex command after all initialization has been performed. See
|
||||||
|
help:initialization[starting.html#Initialization].
|
||||||
|
________________________________________________________________________________
|
||||||
|
|
||||||
|
|
||||||
|
|\++cmd| +
|
||||||
|
||\++cmd={command}||
|
||||||
|
________________________________________________________________________________
|
||||||
|
Execute a single Ex command before any initialization has been performed. See
|
||||||
|
help:initialization[starting.html#Initialization].
|
||||||
|
________________________________________________________________________________
|
||||||
|
|
||||||
|
|
||||||
|
|+u| +
|
||||||
|
||+u={rcfile}||
|
||||||
|
________________________________________________________________________________
|
||||||
|
The file {rcfile} is used for user initialization commands. If {rcfile} is
|
||||||
|
"NORC" then no startup initialization is performed except for the loading of
|
||||||
|
plugins, i.e. steps 1. and 2. in
|
||||||
|
help:initialization[starting.html#Initialization] are skipped. If {rcfile} is
|
||||||
|
"NONE" then plugin loading is also skipped.
|
||||||
|
________________________________________________________________________________
|
||||||
|
|
||||||
|
|
||||||
|
|\++noplugin| +
|
||||||
|
||\++noplugin||
|
||||||
|
________________________________________________________________________________
|
||||||
|
Prevents plugin scripts from being loaded at startup. See 'loadplugins'.
|
||||||
|
________________________________________________________________________________
|
||||||
|
|
||||||
section:Initialization[initialization,startup]
|
section:Initialization[initialization,startup]
|
||||||
|
|
||||||
@@ -18,15 +54,21 @@ further locations are tried.
|
|||||||
are executed and _$MY_VIMPERATORRC_ set to its path.
|
are executed and _$MY_VIMPERATORRC_ set to its path.
|
||||||
c. _\~/.vimperatorrc_ -- If this file exists, its contents are executed.
|
c. _\~/.vimperatorrc_ -- If this file exists, its contents are executed.
|
||||||
|
|
||||||
2. If 'exrc' is set, then any RC file in the current directory is also sourced.
|
2. If 'exrc' is set and the +u command-line option was not specified, then any
|
||||||
|
RC file in the current directory is also sourced.
|
||||||
|
|
||||||
3. All directories in 'runtimepath' are searched for a "plugin"
|
3. All directories in 'runtimepath' are searched for a "plugin"
|
||||||
subdirectory and all yet unloaded plugins are loaded. For each
|
subdirectory and all yet unloaded plugins are loaded. For each
|
||||||
plugin directory, all *.\{js,vimp} files (including those in further
|
plugin directory, all *.\{js,vimp} files (including those in further
|
||||||
subdirectories) are sourced alphabetically. No plugins will be sourced
|
subdirectories) are sourced alphabetically. No plugins will be sourced
|
||||||
if 'noloadplugins' is set. Any particular plugin will not be loaded
|
if:
|
||||||
if it has already been loaded (e.g., by an earlier [c]:loadplugins[c]
|
|
||||||
command).
|
* 'noloadplugins' is set.
|
||||||
|
* the \++noplugin command-line option was specified.
|
||||||
|
* the +u=NONE command-line option specified set.
|
||||||
|
|
||||||
|
Any particular plugin will not be loaded if it has already been loaded (e.g.,
|
||||||
|
by an earlier [c]:loadplugins[c] command).
|
||||||
|
|
||||||
The user's ~ (i.e., "home") directory is determined as follows:
|
The user's ~ (i.e., "home") directory is determined as follows:
|
||||||
|
|
||||||
|
|||||||
39
xulmus/components/commandline-handler.js
Normal file
39
xulmus/components/commandline-handler.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
|
|
||||||
|
function CommandLineHandler()
|
||||||
|
{
|
||||||
|
this.wrappedJSObject = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandLineHandler.prototype = {
|
||||||
|
|
||||||
|
classDescription: "Liberator Command-line Handler",
|
||||||
|
|
||||||
|
classID: Components.ID("{16dc34f7-6d22-4aa4-a67f-2921fb5dcb69}"),
|
||||||
|
|
||||||
|
contractID: "@mozilla.org/commandlinehandler/general-startup;1?type=liberator",
|
||||||
|
|
||||||
|
_xpcom_categories: [{
|
||||||
|
category: "command-line-handler",
|
||||||
|
entry: "m-liberator"
|
||||||
|
}],
|
||||||
|
|
||||||
|
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsICommandLineHandler]),
|
||||||
|
|
||||||
|
handle: function (commandLine)
|
||||||
|
{
|
||||||
|
// TODO: handle remote launches differently?
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.optionValue = commandLine.handleFlagWithParam("liberator", false);
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
//"liberator: option -liberator requires an argument"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function NSGetModule(compMgr, fileSpec) XPCOMUtils.generateModule([CommandLineHandler]);
|
||||||
|
|
||||||
|
// vim: set fdm=marker sw=4 ts=4 et:
|
||||||
Reference in New Issue
Block a user