keysnail icon indicating copy to clipboard operation
keysnail copied to clipboard

Make prompt for g and C-x C-f use location bar algorithm.

Open jeeger opened this issue 10 years ago • 2 comments

It would be awesome if I could bind 'g' and 'C-x C-f' to a dialog that accesses history and search information the way the location bar does it. For example, if I enter "keysnail", I get a list of URLs that I've visited that contain the word keysnail, or if I enter "google test", it uses Google to search for the word "test", the way the location bar does. This way, it would be possible to hide the location bar and rely on keysnail functionality.

jeeger avatar Jan 21 '15 10:01 jeeger

It turns out in bmany.ks.js, just above the line of const bmService = PlacesUtils.bookmarks;, there's a const histService = PlacesUtils.history;. While bmService is used elsewhere in the script as expected, histService is not. So bmany was probably intended to provide search for both bookmarks and history in the very beginning, but the history part was dropped for some reason, which only @mooz knows(maybe difference in api made it difficult).

Just while writing this, I found that there is a history search plugin in the plugin wiki, @958 's history from keysnail. You just need to read the menu again and again 🤒.

For the "google" functionality, I found @958 's quickggl.ks.js and quickbing.ks.js. None of them is on the plugin wiki page, so I'm really lucky the search engine listed them.

However a plugin script for each search engine/site is kind of redundant, it would be really nice if someone writes a plugin (and it be on the wiki) which lets you define "site template"-"key" pairs/map, e.g. "github.com/%s"-"['C-x', 'g', 'u']" ("github user shortcut") in your config lets you go to "github.com/mooz" by pressing keys -> type "mooz" -> enter .

JJPandari avatar Apr 10 '17 03:04 JJPandari

Turns out "opening with a template" is easy to implement. Just need to know prompt.read and openUILinkIn. Here is my code (using SPC as leader key like spacemacs):

const JJ_TAB_CURRENT = 'current';
const JJ_TAB_NEW = 'tab';

const openConfigs = [
    {
        keys: ['o'],
        place: JJ_TAB_CURRENT,
        template: '%s',
        msg: 'open:',
        description: 'open in current tab'
    },
    {
        keys: ['O'],
        template: '%s',
        msg: 'open:',
        description: 'open in new tab'
    },
    {
        keys: [['SPC', 'SPC']],
        template: 'http://cn.bing.com/search?q=%s',
        msg: 'Bing:',
        description: 'search with bing'
    },
    {
        keys: ['SPC', 'g', 'g'],
        template: 'http://www.google.com/search?q=%s',
        msg: 'Google:',
        description: 'search with google'
    },
    {
        keys: ['SPC', 'd', 'd', 'g'],
        template: 'http://duckduckgo.com/?q=%s',
        msg: 'DuckDuckGo:',
        description: 'search with DuckDuckGo'
    },
    {
        keys: ['SPC', 's', 's'],
        template: 'http://cn.bing.com/search?q=%s+site:stackoverflow.com',
        msg: 'search stackoverflow:',
        description: 'search stackoverflow with bing'
    }
];

openConfigs.forEach(conf => {
    key.setViewKey(conf.keys, function (ev, arg) {
        prompt.read(conf.msg, function (input) {
            if (input)
                openUILinkIn(
                    conf.template.replace('%s', input.replace(/\s/g, '+')),
                    conf.place || JJ_TAB_NEW
                );
            // use msg as history namespace
        }, null, null, null, 0, conf.msg);
    }, conf.description);
});

JJPandari avatar Apr 11 '17 03:04 JJPandari