Skip to content

Instantly share code, notes, and snippets.

@davidwollmann
Created August 16, 2009 01:03
Show Gist options
  • Select an option

  • Save davidwollmann/168512 to your computer and use it in GitHub Desktop.

Select an option

Save davidwollmann/168512 to your computer and use it in GitHub Desktop.
Mozilla Ubiquity command for searching CPAN, perldoc and perlmonks.org
// Based on original command authored by Siddhartha Reddy and hosted
// at http://www.grok.in/ubiquity/perl.html
// Siddhartha Reddy <sids@grok.in>
//
// Updated to work with Parser 2: https://wiki.mozilla.org/Labs/Ubiquity/Parser_2
function makeSearchCommand( options ) {
options.homepage = "http://gist.github.com/168512";
options.author = { name: "David Wollmann", email: "converter42@gmail.com"};
options.license = "MPL";
options.icon = "http://search.cpan.org/favicon.ico";
options['arguments'] = [
{ role: 'object', nountype: noun_arb_text, label: 'search term' }
];
if (! options.preview ) {
options.preview = function(pblock, args) {
var data = {};
data.properName = options.properName;
data.query = args.object.text;
var template = "Performs a ${properName} search";
if(data.query.length > 0) {
template += " for ${query}";
}
pblock.innerHTML = CmdUtils.renderTemplate(template, data);
};
}
options.execute = function(args) {
var query = args.object.text;
var urlString = options.url.replace("{QUERY}", query);
Utils.openUrlInBrowser(urlString);
CmdUtils.setLastResult( urlString );
};
CmdUtils.CreateCommand(options);
}
makeSearchCommand({
names: ["perldoc"],
properName: 'perldoc',
url: "http://perldoc.perl.org/search.html?q={QUERY}",
description: "Search http://perldoc.perl.org/ for the specified Perl terms."
});
makeSearchCommand({
names: ["cpan"],
properName: 'CPAN',
url: "http://search.cpan.org/search?query={QUERY}&mode=all",
description: "Search http://search.cpan.org/ for the specified perl modules."
});
makeSearchCommand({
names: ["monks"],
properName: 'perlmonks.org',
url: "http://www.perlmonks.org/?node={QUERY}",
description: "Search http://perlmonks.org/ for the specified terms."
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment