surf

surf
git clone git@git.zachrice.app:repos/surf.git
Log | Files | Refs | README | LICENSE

surf-search.diff (1962B)


      1 Description: Add DuckDuckGo search via Ctrl+s with dmenu prompt
      2 Adds a SEARCHPROP macro and Ctrl+s keybinding that opens a dmenu prompt
      3 labeled "Search:", URL-encodes the query, and navigates to DuckDuckGo.
      4 Change SEARCH_URL in config.def.h to use a different search engine.
      5 
      6 Apply:   patch -p1 < patches/surf-search.diff
      7 Unpatch: patch -R -p1 < patches/surf-search.diff
      8 
      9 diff --git a/config.def.h b/config.def.h
     10 index d38966c..ea29f8c 100644
     11 --- a/config.def.h
     12 +++ b/config.def.h
     13 @@ -63,8 +63,23 @@ static int winsize[] = { 800, 600 };
     14  static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE |
     15                                      WEBKIT_FIND_OPTIONS_WRAP_AROUND;
     16  
     17 -#define PROMPT_GO   "Go:"
     18 -#define PROMPT_FIND "Find:"
     19 +#define PROMPT_GO     "Go:"
     20 +#define PROMPT_FIND   "Find:"
     21 +#define PROMPT_SEARCH "Search:"
     22 +
     23 +#define SEARCH_URL "https://duckduckgo.com/?q="
     24 +
     25 +/* SEARCHPROP(prompt) — dmenu prompt, URL-encode input, navigate via _SURF_GO */
     26 +#define SEARCHPROP(p) { \
     27 +        .v = (const char *[]){ "/bin/sh", "-c", \
     28 +             "prop=\"$(dmenu -p '"p"' -w $1 </dev/null" \
     29 +             " | sed 's/ /+/g')\"" \
     30 +             " && [ -n \"$prop\" ]" \
     31 +             " && xprop -id $1 -f _SURF_GO 8u -set _SURF_GO" \
     32 +             " \""SEARCH_URL"$prop\"", \
     33 +             "surf-search", winid, NULL \
     34 +        } \
     35 +}
     36  
     37  /* SETPROP(readprop, setprop, prompt)*/
     38  #define SETPROP(r, s, p) { \
     39 @@ -144,6 +159,7 @@ static SiteSpecific certs[] = {
     40  static Key keys[] = {
     41  	/* modifier              keyval          function    arg */
     42  	{ MODKEY,                GDK_KEY_g,      spawn,      SETPROP("_SURF_URI", "_SURF_GO", PROMPT_GO) },
     43 +	{ MODKEY,                GDK_KEY_s,      spawn,      SEARCHPROP(PROMPT_SEARCH) },
     44  	{ MODKEY,                GDK_KEY_f,      spawn,      SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) },
     45  	{ MODKEY,                GDK_KEY_slash,  spawn,      SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) },
     46