Bzr and launchpad tricks: firefox plugin
If you work with bazaar, you have seen its URIs. You can find the complete list is in the bzr help urlspec. Although I commonly use only a subset of that, like bzr+ssh://bazaar.launchpad.net/~maria-captains/maria/5.2-serg/ and http://bazaar.launchpad.net/%2Bbranch/mysql-server/5.5/.
In addition I often use Launchpad aliases, such as lp:~maria-captains/maria/5.3-serg/, lp:maria/5.3, and lp:869001.
And finally, there are common abbreviations that we have used in MySQL, and others that we use in MariaDB, for example bug#12345 and wl#90.
What’s annoying, I need to remember that wl#90 corresponds to http://askmonty.org/worklog/?tid=90 and type the latter in the location bar of the browser, when I want to look this task up. And lp:869001 is, for my browser, https://bugs.launchpad.net/bugs/869001. Similarly, every other URL above, has its browser-friendly evil twin. It’s evil, because I have to remember it!
Now, Firefox tries to help, to a certain extent. It supports so-called keywords — short aliases for bookmarks. Create a bookmark for https://bugs.launchpad.net/bugs/%s and in the Keyword field enter lp. Now you can type in the location bar lp 869001 (with a space) and Firefox will expand it into a complete url https://bugs.launchpad.net/bugs/869001. Quite handy. And I’ve used it for a few years. Still it annoyed me, that I had to rewrite the abbreviations manually, put spaces, remove colons, and so on. And at last it annoyed me to a degree where I wrote a Firefox plugin!
Let me introduce a LocationMorph — a plugin that can arbitrarily rewrite the text in the location bar, according to the user specified regular expression. I have configured it (via a Preference dialog) to use the following set of rules
^bzr+ssh://bazaar.launchpad.net/ → http://code.launchpad.net/ ^lp:(d+)$ → https://bugs.launchpad.net/bugs/$1 ^lp: → http://code.launchpad.net/ ^wl#(d+)$ → http://askmonty.org/worklog/?tid=$1 ^bug#(d+)$ → http://bugs.mysql.com/bug.php?id=$1
And now I can simply copy and paste a bzr URI, or a launchpad alias, or our internal abbreviation from the email (or bzr info) directly into the browser, and it understands it directly and shows me the page that I want. Ahh, perfection…
It’s great! I like the test option in the preferences.
The only improvement I can think of would be downloadable rulesets:
Go to some website and download a file which lists a few rules which are specific for that website.
This could also use an auto-update mechanism. Of course this could result in a security risk if implemented badly.
Thanks!
Yes, I thought about it, but then – I didn’t see it being used with hundreds of different rules, and rulesets that needs to be updated. AdBlock is doing it, right, but I can hardly imagine why anyone would need that many url rewrite rules.
But I might be wrong about it 🙂
Then I will think about implementing rulesets.
Thanks for updating it to the current Firefox version. I used lp:URI before it (and LocationMorph) became incompatible with FF 4.
yes, lp:URI was my first attempt to solve this problem. It used a different approach, which could not be extended to handle other URI patterns. Now I’ve completely abandoned lp:URI in favor of LocationMorph.
You can already define bug as a keyword to take you to a bug in Firefox, no plugin needed A search online for the string firefox keyword will take you to lots of tutorials.
Create a new shortcut.
Name: bug (or anything else)
Location: http://bugs.mysql.com/%s
Keyword: bug
Save it.
Now you can type bug 12345 and you’ll be taken to that bug. You can apply the same technique for the others you’ve given.
Simple keywords not enough? Try javascript. Alternative bug with prompt that you can make a shortcut with this as the URI:
javascript:bug=prompt(‘Bug to open’,”);if(bug){location.href=’http://bugs.mysql.com/’+bug;}else{void(null)}
You can use javascript’s replace method to modify the strings as required using simple string matches or regular expressions.
A required disclosure: I’m an employee of Oracle but my words do not represent the official position of Oracle, just my own opinion. For an official company view seek out an Oracle press contact.
Replying before reading, eh?
I’ve described firefox keywords in the post, together with explanation why they aren’t enough.
And although javascript in a keyword is an interesting technique (I’m using keywords and bookmarklets, but never thought about combining them), I doubt it can solve the problem.
The whole point was to paste the abbreviation into the browser (I usually just select the bug reference in the email and click the middle mouse button somewhere in the browser window) without further editing or answering any questions.
I like it, but as James writes, Firefox already supports keywords. Your extension can do much more, but the examples (except for the first) don’t really show that. E.g. I could do this with your extension:
^route ([^ ]*) ([^ ]*) => http://maps.google.com/maps?saddr=$1&daddr=$2
One thing that would be nice is if the extension worked when a new tab is opened by invoking firefox from the command line. That doesn’t seem to work now. It’ll interpret it as an incomplete file:// URL. Matching the kind of URL it would try to load still requires me to click the location bar and hit return. If this worked, I could configure my terminal to open some more URL schemes in firefox, e.g. bzr+ssh://.
Command-line – it’s a good idea, I’ll look into it.
Thanks!