Implement search engines.
This commit is contained in:
parent
acd7a0a070
commit
31fd8282da
1
TODO
1
TODO
@ -21,7 +21,6 @@ webinterface for settings/colors/bindings
|
|||||||
Before Blink
|
Before Blink
|
||||||
------------
|
------------
|
||||||
|
|
||||||
searchengines
|
|
||||||
session handling / saving
|
session handling / saving
|
||||||
IPC, like dwb -x
|
IPC, like dwb -x
|
||||||
Mode handling?
|
Mode handling?
|
||||||
|
@ -17,11 +17,13 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import os.path
|
import os.path
|
||||||
import platform
|
import platform
|
||||||
import logging
|
import logging
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import urllib.parse
|
||||||
|
|
||||||
from PyQt5.QtCore import QUrl, QT_VERSION_STR, PYQT_VERSION_STR, qVersion
|
from PyQt5.QtCore import QUrl, QT_VERSION_STR, PYQT_VERSION_STR, qVersion
|
||||||
from PyQt5.QtWebKit import qWebKitVersion
|
from PyQt5.QtWebKit import qWebKitVersion
|
||||||
@ -34,11 +36,42 @@ def qurl(url):
|
|||||||
if isinstance(url, QUrl):
|
if isinstance(url, QUrl):
|
||||||
logging.debug("url is already a qurl")
|
logging.debug("url is already a qurl")
|
||||||
return url
|
return url
|
||||||
|
elif '.' in url or is_about_url(url): # probably an address
|
||||||
|
logging.debug("url is a fuzzy address")
|
||||||
|
newurl = QUrl.fromUserInput(url)
|
||||||
|
else: # probably a search term
|
||||||
|
logging.debug("url is a fuzzy search term")
|
||||||
|
try:
|
||||||
|
newurl = QUrl.fromUserInput(_get_search_url(url))
|
||||||
|
except ValueError:
|
||||||
newurl = QUrl.fromUserInput(url)
|
newurl = QUrl.fromUserInput(url)
|
||||||
logging.debug('Converting {} to qurl -> {}'.format(url, newurl.url()))
|
logging.debug('Converting {} to qurl -> {}'.format(url, newurl.url()))
|
||||||
return newurl
|
return newurl
|
||||||
|
|
||||||
|
|
||||||
|
def _get_search_url(txt):
|
||||||
|
"""Get a search engine URL for a text."""
|
||||||
|
# FIXME Importing this here fixes some weird dependency problems.
|
||||||
|
import qutebrowser.utils.config as config
|
||||||
|
logging.debug('Finding search engine for "{}"'.format(txt))
|
||||||
|
r = re.compile(r'(^|\s+)!(\w+)($|\s+)')
|
||||||
|
m = r.search(txt)
|
||||||
|
if m:
|
||||||
|
engine = m.group(2)
|
||||||
|
# FIXME why doesn't fallback work?!
|
||||||
|
template = config.config.get('searchengines', engine, fallback=None)
|
||||||
|
term = r.sub('', txt)
|
||||||
|
logging.debug('engine {}, term "{}"'.format(engine, term))
|
||||||
|
else:
|
||||||
|
template = config.config.get('searchengines', '__default__',
|
||||||
|
fallback=None)
|
||||||
|
term = txt
|
||||||
|
logging.debug('engine: default, term "{}"'.format(txt))
|
||||||
|
if template is None or not term:
|
||||||
|
raise ValueError
|
||||||
|
return template.format(urllib.parse.quote(term))
|
||||||
|
|
||||||
|
|
||||||
def version():
|
def version():
|
||||||
"""Return a string with various version informations."""
|
"""Return a string with various version informations."""
|
||||||
if sys.platform == 'linux':
|
if sys.platform == 'linux':
|
||||||
|
@ -40,6 +40,15 @@ default_config = """
|
|||||||
wrapsearch = true
|
wrapsearch = true
|
||||||
startpage = http://www.duckduckgo.com/
|
startpage = http://www.duckduckgo.com/
|
||||||
|
|
||||||
|
[searchengines]
|
||||||
|
duckduckgo = https://duckduckgo.com/?q={}
|
||||||
|
ddg = ${duckduckgo}
|
||||||
|
google = https://encrypted.google.com/search?q={}
|
||||||
|
g = ${google}
|
||||||
|
wikipedia = http://en.wikipedia.org/w/index.php?title=Special:Search&search={}
|
||||||
|
wiki = ${wikipedia}
|
||||||
|
__default__ = ${duckduckgo}
|
||||||
|
|
||||||
[keybind]
|
[keybind]
|
||||||
o = open
|
o = open
|
||||||
go = opencur
|
go = opencur
|
||||||
|
Loading…
Reference in New Issue
Block a user