surf-uri-aliases-20220930-089272b.diff (1532B)
1 From 089272be1459bc91800215d39f483a2584ae99cc Mon Sep 17 00:00:00 2001 2 From: r4v10l1 <29655971+r4v10l1@users.noreply.github.com> 3 Date: Fri, 30 Sep 2022 18:59:15 +0200 4 Subject: [PATCH] Alias patch 5 6 --- 7 config.def.h | 7 +++++++ 8 surf.c | 12 ++++++++++++ 9 2 files changed, 19 insertions(+) 10 11 diff --git a/config.def.h b/config.def.h 12 index 93cfeeb..2b19183 100644 13 --- a/config.def.h 14 +++ b/config.def.h 15 @@ -194,3 +194,10 @@ static Button buttons[] = { 16 { OnAny, 0, 9, clicknavigate, { .i = +1 }, 1 }, 17 { OnMedia, MODKEY, 1, clickexternplayer, { 0 }, 1 }, 18 }; 19 + 20 +/* Put here your aliases */ 21 +static Alias aliases[] = { 22 + /* Alias URI */ 23 + { "ddg", "https://duckduckgo.com" }, 24 + { "wikipedia", "https://www.wikipedia.org" } 25 +}; 26 diff --git a/surf.c b/surf.c 27 index 474c01b..25f8528 100644 28 --- a/surf.c 29 +++ b/surf.c 30 @@ -144,6 +144,11 @@ typedef struct { 31 regex_t re; 32 } SiteSpecific; 33 34 +typedef struct { 35 + const char* alias; 36 + const char* uri; 37 +} Alias; 38 + 39 /* Surf */ 40 static void die(const char *errstr, ...); 41 static void usage(void); 42 @@ -567,6 +572,13 @@ loaduri(Client *c, const Arg *a) 43 if (g_strcmp0(uri, "") == 0) 44 return; 45 46 + for (int i = 0; i < LENGTH(aliases); i++) { 47 + if (strcmp(aliases[i].alias, uri) == 0) { 48 + uri = aliases[i].uri; 49 + break; 50 + } 51 + } 52 + 53 if (g_str_has_prefix(uri, "http://") || 54 g_str_has_prefix(uri, "https://") || 55 g_str_has_prefix(uri, "file://") || 56 -- 57 2.37.3 58