From b142f26cfa74b14cb89c01a26c23bd9ed30cb52f Mon Sep 17 00:00:00 2001 From: Michal Mazurek Date: Tue, 2 Aug 2011 20:45:24 +0000 Subject: Add the 'go up' buffer command. This is diff bcmd #1 ok marco --- xxxterm.1 | 8 ++++++++ xxxterm.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) 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 @@ -6736,6 +6738,42 @@ qmark(struct tab *t, struct karg *arg) return (0); } +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) { @@ -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 }, -- cgit 1.4.1-2-gfad0