commit ff17eea92e0f7feac2ee8748cdd12b41fd3431ca
Author: Justinas Grigas <jstn_as_AT_protonmail.com>
Date: Fri Aug 5 00:18:20 2022 +0300
[surf][patch][searchengines] added updated patch
fixes issues with the previous patches
diff --git a/surf.suckless.org/patches/searchengines/index.md b/surf.suckless.org/patches/searchengines/index.md
index 111ed908..9fdea062 100644
--- a/surf.suckless.org/patches/searchengines/index.md
+++ b/surf.suckless.org/patches/searchengines/index.md
_AT_@ -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
_AT_@ -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
--------
_AT_@ -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
------
_AT_@ -41,3 +46,4 @@ Author
* Alex Puterbaugh (zombine) <puterbaugh0_AT_gmail.com>
* Ivan Tham (pickfire) <pickfire_AT_riseup.net>
* Juan Aguilar Santillana (botika) <aritmeeul_AT_gmail.com>
+* Justinas Grigas - <jstn_as_AT_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
new file mode 100644
index 00000000..32aca05e
--- /dev/null
+++ b/surf.suckless.org/patches/searchengines/surf-searchengines-20220804-609ea1c.diff
_AT_@ -0,0 +1,94 @@
+From 2f64431f15777d93d146707dccdb6ad063c7a316 Mon Sep 17 00:00:00 2001
+From: Justinas Grigas <jstn_as_AT_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
+_AT_@ -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
+_AT_@ -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];
+_AT_@ -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);
+_AT_@ -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);
+_AT_@ -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
+
Received on Thu Aug 04 2022 - 23:21:42 CEST