User Tools

Site Tools


go-to

Go To

Description

Detects wether input is a web page or a search phrase. If you type “o uzbl wiki” google will be queried on uzbl wiki, if you type “o uzbl.org” uzbl.org will be opened as a web page

Perl

#!/usr/bin/perl

my ($config,$pid,$xid,$fifo,$socket,$url,$title,@cmd) = @ARGV;
if($fifo eq "") { die "No fifo"; };

#If there are no dots in the first word or more than one word is suppllied expect a phrase for google. Else go to the uri specified.
if (index(@cmd[0], '.') == -1 || scalar @cmd > 1)
{
        # Replace this with your search engine
	qx(echo "uri http://www.google.de/search?q=@cmd" >> $fifo);
}
else
{
	qx(echo "uri @cmd" >> $fifo);
}

Installation

Copy the above script to a directory of your choice and bind it for example with:

@bind o _ = spawn @scripts_dir/goto.pl %s

Javascript

The above version did not work very well for me, so I created a JS version that does:

var o = '%s';
if(o.indexOf('.') > 0){
    if(o.indexOf(':') < 0) o = 'http://' + o
    window.location = o;
} else window.location = 'http://www.google.com/search?q=' + o + '&btnI=I\'m+Feeling+Lucky'

Installation

Copy the above script to a directory of your choice and bind it for example with:

@bind o _ = script @scripts_dir/goto.js '%s'

Python

A more powerful version, surfraw_goto.py:

#!/usr/bin/python
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the -Do What The Fuck You Want
# To Public License-, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.

# A script helping to use various search-engines (using surfraw)
#
# In order to use surfraw, e.g searching for "uzbl" with
# http://www.google.com/linux, we would call surfraw like this:
# "surfraw -p google --search=linux uzbl".
# Use this script to simplify using surfraw, e.g. calling this script with
# "google linux uzbl" for loading the right website.

#############
# There is the posibility to define bookmarks in /etc/surfraw.bookmarks
# but the are ignored. It is easy to support them, but it is easier to
# configure your webjumps in you uzbl-config file.
# Configure your countrycode in /etc/surfraw.conf.
#############

import sys
import subprocess

pref_search = "google"

# Sometimes there are conflicts with evlis. "wiki" would turn into
# "wiki.debian.com" and not into into "wikipedia.org" as one might want.
# So define your alias here. Useful to shorten long namens.
# In addition you can assign options.
ALIASES = {"leo":["leodict"], "leoen":["leodict", "-to=en -lang=de"],
               "leode":["leodict", "-to=de -lang=de"], "wiki":["wikipedia"]}

# Surfraw is mighty. To use this define your options here.
# Look at "surfraw [elvi] --help" for a list of options.
OPTIONS = {"google":{"linux":"-search=linux", "bsd":"-search=bsd"}}

# This list seldom changes. So why generating is every time?
ELVIS = ['alioth', 'altavista', 'amazon', 'archpkg', 'arxiv', 'ask', 'aur',
        'austlii', 'bbcnews', 'cddb', 'cia', 'cite', 'cnn', 'codesearch',
        'comlaw', 'ctan', 'currency', 'cve', 'debbugs', 'debcontents',
        'deblists', 'deblogs', 'debpackages', 'debpts', 'debsec', 'debwiki',
        'deja', 'discogs', 'dmoz', 'ebay', 'etym', 'excite', 'fast',
        'filesearching', 'foldoc', 'freebsd', 'freedb', 'freshmeat',
        'fsfdir', 'genpkg', 'genportage', 'google', 'gutenberg',
        'happypenguin', 'imdb', 'ixquick', 'javasun', 'lastfm', 'leodict',
        'lsm', 'musicbrainz', 'netbsd', 'ntrs', 'openbsd', 'opensearch',
        'pgpkeys', 'piratebay', 'port', 'pubmed', 'rae', 'rfc', 'rhyme',
        'scholar', 'scicom', 'scpan', 'slashdot', 'slinuxdoc', 'sourceforge',
        'springer', 'stockquote', 'sunonesearch', 'thesaurus', 'translate',
        'urban', 'w3css', 'w3html', 'w3link', 'w3rdf', 'wayback', 'webster',
        'wetandwild', 'wikipedia', 'woffle', 'yahoo', 'yubnub']

def use_sr(elvi, keywords, options=[]):
    try:
        sr_cmd = ["surfraw", "-p",  elvi] + options + keywords
        sr = subprocess.Popen(sr_cmd, stdout = subprocess.PIPE)
        sr_stdout = sr.communicate()[0].strip()
    except OSError:
        exit("I can't find surfraw. Is it installed?")
    return sr_stdout

def apply_aliases(args):
    for alias in ALIASES.keys():
        if alias == args[0]:
            args = ALIASES[alias] + args[1:]
            break
    return args

def get_uri(args):
    if args[0] in ELVIS:
        elvi = args[0]
        args = args[1:]
        sr_options = []
        if elvi in OPTIONS:
            elvi_options = OPTIONS[elvi]
            for option in elvi_options:
                if option in args:
                    args.remove(option)
                    sr_options.append(elvi_options[option])
    try:
        uri = use_sr(elvi, args, sr_options)
    except NameError:
        uri = use_sr(pref_search, args)
    return uri

def main():
    args = [arg for arg in sys.argv[8:] if arg]
    args = apply_aliases(args)
    uri = get_uri(args)

    with open(sys.argv[4], 'a') as f:
        f.write("set uri = %s\n" %uri)

if __name__ == "__main__":
    main()

Installation

Copy the above script to a directory of your choice and bind it for example with:

@cbind  ss<Search:>_       = spawn $XDG_DATA_HOME/uzbl/scripts/surfraw_goto.py %s
go-to.txt · Last modified: 2016/08/31 14:10 (external edit)