Yesterday I wrote about how to configure my web browser of choice, Conkeror, to handle Git URIs, causing Conkeror to clone a repository when I browse to its
git:// URI. I did this because I am always cloning repositories from GitHub to read through.
At the end of yesterday’s article I claimed to be able to make Conkeror clone a repository by pressing only three keys. Today I’ll show how.
A Crash Course in Conkeror Commands
First I need to explain how basic commands work in Conkeror. They take the form
<object> <verb>, where one key represents each possibility. Here are some built-in objects and their keys:
And some verbs:
You combine these for common tasks. For example, you press
i s to save an image,
m b to bookmark a frame,
e c to copy the URL to media such as a YouTube video, et cetera. Once you become accustomed to this structure you can accomplish things quickly, without ever having to touch the mouse.
So what does this have to do with cloning GitHub repositories?
It is possible to create custom objects in Conkeror, objects that make it possible to interact with arbitrary elements of a site. Thanks to the script I wrote yesterday Conkeror will clone repositories for me when I browse to their URIs. But when I press
n f (‘follow link’) Conkeror will give me the choice to select any URL. I don’t want that. Instead I want an object that represents Git URIs and nothing else.
Enter the code for a custom browser object:
define_browser_object_class( "git-uri", "Browser object for selecting Git URIs.", xpath_browser_object_handler("//a[starts-with(@href, 'git://')]"), $hint = "git:// URIs" );
As the documentation string says—the second argument—this creates a browser object for Git URIs. I describe the page elements I want by using an XPath expression. That noisy expression in the third argument means this: Select any
<a> tag whose
href attribute begins with
git://. In other words it creates a browser object that targets only those links beginning with the Git scheme.
In order to use the object I must bind it to a key. A common practice is to use the asterisk for custom browser objects. I use this:
define_key(content_buffer_normal_keymap, "* g", "browser-object-git-uri");
The mnemonic for
* g is easy:
* indicates a custom browser object and
g represents Git URIs. Now I can press
* g to use Git URIs as objects to all of Conkeror’s verbs. You may have already realized how this accomplishes what I set out to do.
Remember that Conkeror automatically clones Git repositories when I browse to their
git:// URI. I can browse them with the
f (‘follow’) command. But now I have a special object that presents only Git URIs as links to follow. With that little bit of code in place I can now clone any repository from GitHub by pressing three keys:
* g f.