about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--xxxterm.18
-rw-r--r--xxxterm.c39
2 files changed, 47 insertions, 0 deletions
diff --git a/xxxterm.1 b/xxxterm.1
index beaa820..f45c766 100644
--- a/xxxterm.1
+++ b/xxxterm.1
@@ -564,6 +564,14 @@ go to the bottom of the page
 go to the 
 .Cm arg
 percent of the page
+.It Cm [0-9]*gU
+go
+.Cm arg
+levels up. If
+.Cm arg
+is missing, 1 is assumed. Going a
+level up means going to a uri obtained from the current one by removing
+the last slash ('/') character and everything that follows it
 .It Cm gh
 open the home page in the current tab
 .It Cm M[a-zA-Z0-9]
diff --git a/xxxterm.c b/xxxterm.c
index 758b198..2a4a0b3 100644
--- a/xxxterm.c
+++ b/xxxterm.c
@@ -352,6 +352,8 @@ struct karg {
 
 #define XT_COLOR_SB_SEPARATOR	"#555555"
 
+#define XT_PROTO_DELIM		"://"
+
 /*
  * xxxterm "protocol" (xtp)
  * We use this for managing stuff like downloads and favorites. They
@@ -6737,6 +6739,42 @@ qmark(struct tab *t, struct karg *arg)
 }
 
 int
+go_up(struct tab *t, struct karg *args)
+{
+	int		 levels;
+	char		*uri;
+	char		*tmp;
+
+	levels = atoi(args->s);
+	if (levels == 0)
+		levels = 1;
+
+	uri = g_strdup(webkit_web_view_get_uri(t->wv));
+	if ((tmp = strstr(uri, XT_PROTO_DELIM)) == NULL)
+		return 1;
+	tmp += strlen(XT_PROTO_DELIM);
+
+	/* if an uri starts with a slash, leave it alone (for file:///) */
+	if (tmp[0] == '/')
+		tmp++;
+
+	while (levels--) {
+		char	*p;
+
+		p = strrchr(tmp, '/');
+		if (p != NULL)
+			*p = '\0';
+		else
+			break;
+	}
+
+	load_uri(t, uri);
+	g_free(uri);
+
+	return 0;
+}
+
+int
 gototab(struct tab *t, struct karg *args)
 {
 	int		tab;
@@ -6771,6 +6809,7 @@ struct buffercmd {
 	int             arg;
 	regex_t		cregex;
 } buffercmds[] = {
+	{ "^[0-9]*gu$",		go_up,		0 },
 	{ "^gg$",               move,           XT_MOVE_TOP },
 	{ "^gG$",               move,           XT_MOVE_BOTTOM },
 	{ "^[0-9]+%$",		move,		XT_MOVE_PERCENT },