Last Updated: February 25, 2016
·
492
· robjens

Easier code search

Today I became motivated to do something I should have done ages ago, or at least ever since GitHub implemented the new search features. Since most of my searches were Clojure, I made this bookmarklet rather static and a blatant copy from the Wikipedia article. Either gives a input dialog if no text is selected or use the selected words as search terms in the query parameter.

Just add a new bookmark to your browser and instead of providing a URL post in this JavaScript instead:

javascript: (function() {
    function se(d) {
        return d.selection ? d.selection.createRange().text : d.getSelection()
    }
    s = se(document);
    for (i = 0; i < frames.length && !s; i++) s = se(frames[i].document);
    if (!s || s == '') s = prompt('Enter search terms for GitHub', '');
   open('https://github.com/search?l=clojure&ref=simplesearch&type=Code&utf8=✓' + (s ? '&q=' + encodeURIComponent(s) : '')).focus();
})();

Tweak as you see fit. Reason I took this route is it will go straight to code so all in all saves me a click plus having to type extension:clojure every time. And if I'm lucky, all I need to do is to highlight those terms that I want to search so optimal workload is click, drag, click and done :)