aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README14
-rw-r--r--uzbl.c118
-rw-r--r--uzbl.h13
3 files changed, 114 insertions, 31 deletions
diff --git a/README b/README
index 71cdcfa..68a3b33 100644
--- a/README
+++ b/README
@@ -128,12 +128,6 @@ Examples:
ACT <action>
This tells uzbl to execute an action immediately. The simplest example of this would be `act exit`; you know what that'll do.
- KEYCMD <string>
-This sets the interactive command buffer to `<string>`. Keycmd is primarily useful for scripts that help you type a command while still letting you edit it before execution.
-For example, if you have a binding like "o _" that opens an URL, then you could create a binding `O` that spawns a script which will set the command buffer to "o current-uri-here", letting you enter relative URLs easily.
-
- KEYCMDN <string>
-Like KEYCMD, but also emulates a press of return which causes binds with an asterisk or underscore to execute.
(See sample config)
### ACTIONS
@@ -175,6 +169,14 @@ actions follows:
- if the optional state is 0, disable insert mode. If 1, enable insert mode.
* `runcmd`
- can be used for running a command such as SET or BIND
+* `keycmd <string>`
+* `keycmd_nl <string>`
+ - keycmd sets the interactive command buffer to `<string>`. If the given string is a valid binding, it will execute. `Keycmd_nl` is like `keycmd`, but it also emulates a press of return, causing bindings with a parameter to execute. For example, `keycmd_nl o google.com` would load the said url if you have a binding like `bind o _ = uri %s`.
+* `keycmd_bs`
+ - erase (backspace) one character from the command buffer
+* `chain <action> <action> ..`
+ - use for chaining multiple actions
+ - remember to quote the actions; one action must come as one parameter
### VARIABLE REPLACEMENT
diff --git a/uzbl.c b/uzbl.c
index ba6655a..ee5c6bb 100644
--- a/uzbl.c
+++ b/uzbl.c
@@ -186,8 +186,48 @@ make_var_to_name_hash() {
}
}
-
/* --- UTILITY FUNCTIONS --- */
+static gchar *
+expand_vars(char *s) {
+
+ char ret[256], /* 256 chars per var name should be safe */
+ *vend;
+ uzbl_cmdprop *c;
+ GString *buf = g_string_new("");
+
+ while(*s) {
+ /* found quotation char */
+ if(*s == '\\') {
+ g_string_append_c(buf, *++s);
+ s++;
+ }
+ /* found variable */
+ else if(*s == '@') {
+ s++;
+ if( (vend = strchr(s, ' ')) ||
+ (vend = strchr(s, '\0')) ) {
+ strncpy(ret, s, vend-s);
+ ret[vend-s] = '\0';
+ if( (c = g_hash_table_lookup(uzbl.comm.proto_var, ret)) ) {
+ if(c->type == TYPE_STR)
+ g_string_append(buf, (gchar *)*c->ptr);
+ else if(c->type == TYPE_INT) {
+ char *b = itos((int)*c->ptr);
+ g_string_append(buf, b);
+ g_free(b);
+ }
+ }
+ s = vend;
+ }
+ }
+ /* every other char */
+ else {
+ g_string_append_c(buf, *s);
+ s++;
+ }
+ }
+ return g_string_free(buf, FALSE);
+}
char *
itos(int val) {
@@ -567,7 +607,11 @@ static struct {char *name; Command command[2];} cmdlist[] =
{ "toggle_insert_mode", {toggle_insert_mode, 0} },
{ "runcmd", {runcmd, NOSPLIT} },
{ "set", {set_var, NOSPLIT} },
- { "dump_config", {act_dump_config, 0} }
+ { "dump_config", {act_dump_config, 0} },
+ { "keycmd", {keycmd, NOSPLIT} },
+ { "keycmd_nl", {keycmd_nl, NOSPLIT} },
+ { "keycmd_bs", {keycmd_bs, 0} },
+ { "chain", {chain, 0} }
};
static void
@@ -747,6 +791,45 @@ new_window_load_uri (const gchar * uri) {
}
static void
+chain (WebKitWebView *page, GArray *argv) {
+ (void)page;
+ gchar *a = NULL;
+ gchar **parts = NULL;
+ guint i = 0;
+ while ((a = argv_idx(argv, i++))) {
+ parts = g_strsplit (a, " ", 2);
+ parse_command(parts[0], parts[1]);
+ g_strfreev (parts);
+ }
+}
+
+static void
+keycmd (WebKitWebView *page, GArray *argv) {
+ (void)page;
+ (void)argv;
+ g_string_assign(uzbl.state.keycmd, argv_idx(argv, 0));
+ run_keycmd(FALSE);
+ update_title();
+}
+
+static void
+keycmd_nl (WebKitWebView *page, GArray *argv) {
+ (void)page;
+ (void)argv;
+ g_string_assign(uzbl.state.keycmd, argv_idx(argv, 0));
+ run_keycmd(TRUE);
+ update_title();
+}
+
+static void
+keycmd_bs (WebKitWebView *page, GArray *argv) {
+ (void)page;
+ (void)argv;
+ g_string_truncate(uzbl.state.keycmd, uzbl.state.keycmd->len - 1);
+ update_title();
+}
+
+static void
close_uzbl (WebKitWebView *page, GArray *argv) {
(void)page;
(void)argv;
@@ -1169,8 +1252,6 @@ setup_regex() {
G_REGEX_UNGREEDY|G_REGEX_OPTIMIZE, 0, NULL);
uzbl.comm.act_regex = g_regex_new("^[Aa][a-zA-Z]*\\s+([^ \\n]+)\\s*([^\\n]*)?$",
G_REGEX_OPTIMIZE, 0, NULL);
- uzbl.comm.keycmd_regex = g_regex_new("^[Kk][a-zA-Z]*\\s+([^\\n]+)$",
- G_REGEX_OPTIMIZE, 0, NULL);
}
static gboolean
@@ -1274,7 +1355,7 @@ cmd_disable_plugins() {
static void
cmd_disable_scripts() {
g_object_set (G_OBJECT(view_settings()), "enable-scripts",
- !uzbl.behave.disable_plugins, NULL);
+ !uzbl.behave.disable_scripts, NULL);
}
static void
@@ -1431,15 +1512,19 @@ static gboolean
set_var_value(gchar *name, gchar *val) {
uzbl_cmdprop *c = NULL;
char *endp = NULL;
+ char *buf = NULL;
if( (c = g_hash_table_lookup(uzbl.comm.proto_var, name)) ) {
/* check for the variable type */
if (c->type == TYPE_STR) {
+ buf = expand_vars(val);
g_free(*c->ptr);
- *c->ptr = g_strdup(val);
+ *c->ptr = buf;
} else if(c->type == TYPE_INT) {
int *ip = (int *)c->ptr;
- *ip = (int)strtoul(val, &endp, 10);
+ buf = expand_vars(val);
+ *ip = (int)strtoul(buf, &endp, 10);
+ g_free(buf);
}
/* invoke a command specific function */
@@ -1529,19 +1614,6 @@ parse_cmd_line(const char *ctl_line) {
else
printf("Error in command: %s\n", tokens[0]);
}
- /* KEYCMD command */
- else if(ctl_line[0] == 'K' || ctl_line[0] == 'k') {
- tokens = g_regex_split(uzbl.comm.keycmd_regex, ctl_line, 0);
- if(tokens[0][0] == 0) {
- /* should incremental commands want each individual "keystroke"
- sent in a loop or the whole string in one go like now? */
- g_string_assign(uzbl.state.keycmd, tokens[1]);
- run_keycmd(FALSE);
- if (g_strstr_len(ctl_line, 7, "n") || g_strstr_len(ctl_line, 7, "N"))
- run_keycmd(TRUE);
- update_title();
- }
- }
/* Comments */
else if( (ctl_line[0] == '#')
|| (ctl_line[0] == ' ')
@@ -1856,10 +1928,8 @@ key_press_cb (GtkWidget* window, GdkEventKey* event)
return TRUE;
}
- if ((event->keyval == GDK_BackSpace) && (uzbl.state.keycmd->len > 0)) {
- g_string_truncate(uzbl.state.keycmd, uzbl.state.keycmd->len - 1);
- update_title();
- }
+ if (event->keyval == GDK_BackSpace)
+ keycmd_bs(NULL, NULL);
gboolean key_ret = FALSE;
if ((event->keyval == GDK_Return) || (event->keyval == GDK_KP_Enter))
diff --git a/uzbl.h b/uzbl.h
index 8618675..a36b3f7 100644
--- a/uzbl.h
+++ b/uzbl.h
@@ -96,7 +96,6 @@ typedef struct {
/* command parsing regexes */
GRegex *set_regex;
GRegex *act_regex;
- GRegex *keycmd_regex;
GRegex *get_regex;
GRegex *bind_regex;
gchar *sync_stdout;
@@ -306,6 +305,18 @@ static void
new_window_load_uri (const gchar * uri);
static void
+chain (WebKitWebView *page, GArray *argv);
+
+static void
+keycmd (WebKitWebView *page, GArray *argv);
+
+static void
+keycmd_nl (WebKitWebView *page, GArray *argv);
+
+static void
+keycmd_bs (WebKitWebView *page, GArray *argv);
+
+static void
close_uzbl (WebKitWebView *page, GArray *argv);
static gboolean