用法:(高手都会想到在 WM 中绑定个 google 的快捷键)
surf url
快捷键:(c 指 Ctrl 键)
c-h: 后退
c-r: 刷新
c-g: 输入 url(需要 dmenu 支援)
c-d: 添加到收藏夹
c-b: 打开收藏夹
我只会这么多,其余看 man。:P
遗憾:
需手动編輯收藏夹条目,位于 ~/.surf/bookmarks 文件中。
下载见附件(i386 版本)。另一个附件伪装得还可以吧。XD
忘了说,我动态编译的这个是 0.4.1 版本,主页:http://surf.suckless.org/
14/01/2011 更新:我给补个 dirty patch,用以收藏夹功能,并顺带将下载目录改到 ~/download 下,而不是家目录:
代码: 全选
diff -r 7a931a352cf9 Makefile
--- a/Makefile Thu Sep 09 11:15:02 2010 +0200
+++ b/Makefile Fri Jan 14 18:30:40 2011 +0800
@@ -20,7 +20,7 @@
${OBJ}: config.h config.mk
-config.h:
+config.h: config.def.h
@echo creating $@ from config.def.h
@cp config.def.h $@
diff -r 7a931a352cf9 config.def.h
--- a/config.def.h Thu Sep 09 11:15:02 2010 +0200
+++ b/config.def.h Fri Jan 14 18:30:40 2011 +0800
@@ -5,6 +5,7 @@
static char *stylefile = ".surf/style.css";
static char *scriptfile = ".surf/script.js";
static char *cookiefile = ".surf/cookies.txt";
+static char *bookmarkfile = ".surf/bookmarks";
static time_t sessiontime = 3600;
#define NOBACKGROUND 0
@@ -14,8 +15,14 @@
p, q, winid, NULL } }
#define DOWNLOAD(d) { \
.v = (char *[]){ "/bin/sh", "-c", \
- "xterm -e \"wget --load-cookies ~/.surf/cookies.txt '$0';\"", \
+ "xterm -e \"wget --load-cookies ~/.surf/cookies.txt '$0' -P ~/download;\"", \
d, NULL } }
+#define GETBOOKMARKS(p, q) { \
+ .v = (char *[]){ "/bin/sh", "-c", \
+ "prop=\"`cat ~/.surf/bookmarks | dmenu`\" &&" \
+ "xprop -id $2 -f $1 8s -set $1 \"$prop\"", \
+ p, q, winid, NULL } }
#define MODKEY GDK_CONTROL_MASK
static Key keys[] = {
/* modifier keyval function arg Focus */
@@ -37,4 +44,6 @@
{ MODKEY, GDK_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND") },
{ MODKEY, GDK_n, find, { .b = TRUE } },
{ MODKEY|GDK_SHIFT_MASK,GDK_n, find, { .b = FALSE } },
+ { MODKEY, GDK_d, bookmarks, { 0 } },
+ { MODKEY, GDK_b, spawn, GETBOOKMARKS("_SURF_URI", "_SURF_GO") },
};
diff -r 7a931a352cf9 surf.c
--- a/surf.c Thu Sep 09 11:15:02 2010 +0200
+++ b/surf.c Fri Jan 14 18:30:40 2011 +0800
@@ -82,6 +82,7 @@
static char *geturi(Client *c);
void gotheaders(SoupMessage *msg, gpointer user_data);
static gboolean initdownload(WebKitWebView *v, WebKitDownload *o, Client *c);
+static void bookmarks(Client *c, const Arg *arg);
static gboolean keypress(GtkWidget *w, GdkEventKey *ev, Client *c);
static void linkhover(WebKitWebView *v, const char* t, const char* l, Client *c);
static void loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c);
@@ -337,6 +338,26 @@
return FALSE;
}
+void
+bookmarks(Client *c, const Arg *arg) {
+ char *uri;
+ char buf[512];
+ FILE *f;
+ gboolean exists = FALSE;
+
+ uri = (char *)webkit_web_view_get_uri(c->view);
+ f = fopen(bookmarkfile, "r+");
+ while(fgets(buf, sizeof buf, f)) {
+ if(strncmp(buf, uri, strlen(uri)) == 0) {
+ exists = TRUE;
+ break;
+ }
+ }
+ if(!exists)
+ fputs(strcat(uri, "\n"), f);
+ fclose(f);
+}
+
gboolean
keypress(GtkWidget* w, GdkEventKey *ev, Client *c) {
guint i;
@@ -692,6 +713,7 @@
cookiefile = buildpath(cookiefile);
scriptfile = buildpath(scriptfile);
stylefile = buildpath(stylefile);
+ bookmarkfile = buildpath(bookmarkfile);
/* request handler */
s = webkit_get_default_session();
代码: 全选
diff -r 7a931a352cf9 Makefile
--- a/Makefile Thu Sep 09 11:15:02 2010 +0200
+++ b/Makefile Sat Jan 15 16:02:08 2011 +0800
@@ -20,7 +20,7 @@
${OBJ}: config.h config.mk
-config.h:
+config.h: config.def.h
@echo creating $@ from config.def.h
@cp config.def.h $@
diff -r 7a931a352cf9 config.def.h
--- a/config.def.h Thu Sep 09 11:15:02 2010 +0200
+++ b/config.def.h Sat Jan 15 16:02:08 2011 +0800
@@ -5,6 +5,7 @@
static char *stylefile = ".surf/style.css";
static char *scriptfile = ".surf/script.js";
static char *cookiefile = ".surf/cookies.txt";
+static char *bookmarkfile = ".surf/bookmarks";
static time_t sessiontime = 3600;
#define NOBACKGROUND 0
@@ -14,8 +15,15 @@
p, q, winid, NULL } }
#define DOWNLOAD(d) { \
.v = (char *[]){ "/bin/sh", "-c", \
- "xterm -e \"wget --load-cookies ~/.surf/cookies.txt '$0';\"", \
+ "xterm -e \"wget --load-cookies ~/.surf/cookies.txt '$0' -P ~/download;\"", \
d, NULL } }
+#define GETBOOKMARKS(p, q) { \
+ .v = (char *[]){ "/bin/sh", "-c", \
+ "prop=$(sel=`cut -d '@' -f 1 ~/.surf/bookmarks | \
+ zenity --list --column='Bookmarks' --width=320 --height=280` && \
+ awk -F@ -v a=\"$sel\" '{if($1==a) print $2}' ~/.surf/bookmarks) &&" \
+ "xprop -id $2 -f $1 8s -set $1 \"$prop\"", \
+ p, q, winid, NULL } }
#define MODKEY GDK_CONTROL_MASK
static Key keys[] = {
/* modifier keyval function arg Focus */
@@ -37,4 +45,6 @@
{ MODKEY, GDK_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND") },
{ MODKEY, GDK_n, find, { .b = TRUE } },
{ MODKEY|GDK_SHIFT_MASK,GDK_n, find, { .b = FALSE } },
+ { MODKEY, GDK_d, bookmarks, { 0 } },
+ { MODKEY, GDK_b, spawn, GETBOOKMARKS("_SURF_URI", "_SURF_GO") },
};
diff -r 7a931a352cf9 surf.c
--- a/surf.c Thu Sep 09 11:15:02 2010 +0200
+++ b/surf.c Sat Jan 15 16:02:08 2011 +0800
@@ -82,6 +82,7 @@
static char *geturi(Client *c);
void gotheaders(SoupMessage *msg, gpointer user_data);
static gboolean initdownload(WebKitWebView *v, WebKitDownload *o, Client *c);
+static void bookmarks(Client *c, const Arg *arg);
static gboolean keypress(GtkWidget *w, GdkEventKey *ev, Client *c);
static void linkhover(WebKitWebView *v, const char* t, const char* l, Client *c);
static void loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c);
@@ -337,6 +338,32 @@
return FALSE;
}
+void
+bookmarks(Client *c, const Arg *arg) {
+ char uri[256];
+ char tit[512];
+ char buf[512];
+ FILE *f;
+ gboolean exists = FALSE;
+
+ memcpy(uri, webkit_web_view_get_uri(c->view), sizeof(uri) - 1);
+ uri[255] = '\0';
+ memcpy(tit, webkit_web_view_get_title(c->view), sizeof(uri) - 1);
+ strcat(tit, "@");
+ strcat(tit, uri);
+
+ f = fopen(bookmarkfile, "r+");
+ while(fgets(buf, sizeof buf, f)) {
+ if(strncmp(buf, tit, strlen(tit)) == 0) {
+ exists = TRUE;
+ break;
+ }
+ }
+ if(!exists)
+ fputs(strcat(tit, "\n"), f);
+ fclose(f);
+}
+
gboolean
keypress(GtkWidget* w, GdkEventKey *ev, Client *c) {
guint i;
@@ -692,6 +719,7 @@
cookiefile = buildpath(cookiefile);
scriptfile = buildpath(scriptfile);
stylefile = buildpath(stylefile);
+ bookmarkfile = buildpath(bookmarkfile);
/* request handler */
s = webkit_get_default_session();