Vimperator: Plugin to set proxies from the command line

December 30, 2010 at 1:18 pm Leave a comment

There are firefox addons to set proxies. These can be useful if you are dealing with a small and fixed set of proxies. Since they generally form part of the menuing system, they can be got at using the emenu command in vimperator. One such example is foxyproxy.

However, if you use a *lot* of proxies this can all become somewhat unwieldy. An alternative is to add the following code to your vimperatorrc file. (Or bundle it up as a plugin, if you prefer).

js >>EOF
var pref = services.services.pref;

function set_proxy(host, port){
    liberator.echo(host + ':' + port);
    pref.setCharPref('network.proxy.http', host);
    pref.setIntPref('network.proxy.http_port', port);
    pref.setBoolPref('network.proxy.share_proxy_settings', true);
    pref.setIntPref('network.proxy.type', 1);
}

function get_proxy_string(){
    proxyType = pref.getIntPref('network.proxy.type');
    if (proxyType == 0){
        return 'no_proxy';
    } else if (proxyType == 1) {
        host = pref.getCharPref('network.proxy.http');
        port = pref.getIntPref('network.proxy.http_port');
        return host + ':' + port;
    } else {
        return 'non_http_proxy';
    }
}

commands.addUserCommand(['noproxy'],
    'Switch off proxy',
    function (args) {
        pref.setIntPref('network.proxy.type', 0);
    },
    {},
    true
);
commands.addUserCommand(['proxy'],
    'Set the proxy',
    function (args){
        switch (args.length) {
            case 0:
                liberator.echo(get_proxy_string());
                break;
            case 1:
                [host] = args;
                port = 3128;
                set_proxy(host, port);
                break;
            case 2:
                [host, port] = args;
                set_proxy(host, port);
                break;
            default:
                liberator.echo('proxy host port')
        }
    },
    {}, true);
EOF

This gives you the commands proxy [host [port]] to get and set the current proxy. And noproxy to clear proxies.

Advertisements

Entry filed under: Uncategorized. Tags: , , , .

Illegal names in vimperator Making 3 Mobile Broadband work with googlemail (and other sites)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


December 2010
M T W T F S S
« Nov   Feb »
 12345
6789101112
13141516171819
20212223242526
2728293031  

%d bloggers like this: