sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit ff17eea92e0f7feac2ee8748cdd12b41fd3431ca
parent b315f3438127d6002e0cb39b619acbb5808687c8
Author: Justinas Grigas <jstn_as@protonmail.com>
Date:   Fri,  5 Aug 2022 00:18:20 +0300

[surf][patch][searchengines] added updated patch

fixes issues with the previous patches

Diffstat:
Msurf.suckless.org/patches/searchengines/index.md | 12+++++++++---
Asurf.suckless.org/patches/searchengines/surf-searchengines-20220804-609ea1c.diff | 94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 103 insertions(+), 3 deletions(-)

diff --git a/surf.suckless.org/patches/searchengines/index.md b/surf.suckless.org/patches/searchengines/index.md @@ -8,8 +8,8 @@ This patch allows the simple use of search engines. Put something like this in your `config.h`: static SearchEngine searchengines[] = { - { "g", "http://www.google.de/search?q=%s" }, - { "leo", "http://dict.leo.org/ende?search=%s" }, + { "g ", "http://www.google.de/search?q=%s" }, + { "leo ", "http://dict.leo.org/ende?search=%s" }, }; Then you can access each search engine by putting its prefix in front of your @@ -21,7 +21,11 @@ or: leo hello -0.6 patch patches the searchengines array into the config.def.h file. +**Note:** tokens should end with a space to prevent matching when trying to +search for a url. Token `"g"` will match `google.com`. + +Using `" "` as your token will give you the functionality of the +[spacesearch](https://surf.suckless.org/patches/spacesearch/) patch. Download -------- @@ -32,6 +36,7 @@ Download * [surf-git-20160127-searchengines.diff](surf-git-20160127-searchengines.diff) * [surf-0.7-webkit2-searchengines.diff](surf-0.7-webkit2-searchengines.diff) (20160108) * [surf-git-20170323-webkit2-searchengines.diff](surf-git-20170323-webkit2-searchengines.diff) +* [surf-searchengines-20220804-609ea1c.diff](surf-searchengines-20220804-609ea1c.diff) Author ------ @@ -41,3 +46,4 @@ Author * Alex Puterbaugh (zombine) <puterbaugh0@gmail.com> * Ivan Tham (pickfire) <pickfire@riseup.net> * Juan Aguilar Santillana (botika) <aritmeeul@gmail.com> +* Justinas Grigas - <jstn_as@protonmail.com> (20220804 version) diff --git a/surf.suckless.org/patches/searchengines/surf-searchengines-20220804-609ea1c.diff b/surf.suckless.org/patches/searchengines/surf-searchengines-20220804-609ea1c.diff @@ -0,0 +1,94 @@ +From 2f64431f15777d93d146707dccdb6ad063c7a316 Mon Sep 17 00:00:00 2001 +From: Justinas Grigas <jstn_as@protonmail.com> +Date: Thu, 4 Aug 2022 23:18:40 +0300 +Subject: [PATCH] searchengines: allows simple use of search engines + +The previous patches had some issues: +* don't apply cleanly to the latest version. +* a space between the token and query is implied, so having " " as a + token means you actually have to use " ". Or if your token is "e", + searching for "example.com" would trigger it. Now you specify the exact + token to look for. +* has checks to skip badly configured search engines. The correct + solution is to configure them right. + +Now it works like a better version of the spacesearch patch, as it +allows you to specify " " as a token +--- + config.def.h | 5 +++++ + surf.c | 22 +++++++++++++++++++++- + 2 files changed, 26 insertions(+), 1 deletion(-) + +diff --git a/config.def.h b/config.def.h +index 075f7d0..7bb9c46 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -8,6 +8,11 @@ static char *cachedir = "~/.local/share/surf/cache/"; + static char *cookiefile = "~/.local/share/surf/cookies.txt"; + static char *historyfile = "~/.local/share/surf/history.txt"; + ++static SearchEngine searchengines[] = { ++ { " ", "https://duckduckgo.com/?q=%s" }, ++ { "osrs ", "https://oldschool.runescape.wiki/?search=%s" }, ++}; ++ + /* Webkit default features */ + /* Highest priority value will be used. + * Default parameters are priority 0 +diff --git a/surf.c b/surf.c +index a2b507c..7e85952 100644 +--- a/surf.c ++++ b/surf.c +@@ -133,6 +133,11 @@ typedef struct { + unsigned int stopevent; + } Button; + ++typedef struct { ++ char *token; ++ char *uri; ++} SearchEngine; ++ + typedef struct { + const char *uri; + Parameter config[ParameterLast]; +@@ -220,6 +225,7 @@ static void webprocessterminated(WebKitWebView *v, + Client *c); + static void closeview(WebKitWebView *v, Client *c); + static void destroywin(GtkWidget* w, Client *c); ++static gchar *parseuri(const gchar *uri); + + /* Hotkeys */ + static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d); +@@ -584,7 +590,7 @@ loaduri(Client *c, const Arg *a) + url = g_strdup_printf("file://%s", path); + free(path); + } else { +- url = g_strdup_printf("http://%s", uri); ++ url = parseuri(uri); + } + if (apath != uri) + free(apath); +@@ -1811,6 +1817,20 @@ destroywin(GtkWidget* w, Client *c) + gtk_main_quit(); + } + ++gchar * ++parseuri(const gchar *uri) ++{ ++ guint i; ++ ++ for (i = 0; i < LENGTH(searchengines); i++) { ++ if (g_str_has_prefix(uri, searchengines[i].token)) ++ return g_strdup_printf(searchengines[i].uri, ++ uri + strlen(searchengines[i].token)); ++ } ++ ++ return g_strdup_printf("http://%s", uri); ++} ++ + void + pasteuri(GtkClipboard *clipboard, const char *text, gpointer d) + { +-- +2.37.1 +