aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-06-15 14:13:35 -0700
committerBruce Hill <bruce@bruce-hill.com>2019-06-15 14:13:35 -0700
commit45a08afbbd4e3bc6b8ab3dfa4735a182f559624f (patch)
tree7885f0dbb6f53e152ff7c0cbaa42b500e1188053
parent1239060641b3a33eeefd7f72c3a53995916e01d8 (diff)
Added `+bind` command to allow for stuff like `bb +"b:\r:echo \$BBCURSOR && bb +q"`
-rw-r--r--bb.c20
-rw-r--r--config.def.h6
2 files changed, 24 insertions, 2 deletions
diff --git a/bb.c b/bb.c
index 0d13f3f..2e9847d 100644
--- a/bb.c
+++ b/bb.c
@@ -986,6 +986,24 @@ bb_result_t process_cmd(bb_t *bb, const char *cmd)
populate_files(bb, bb->path);
return BB_OK;
}
+ case 'b': { // +bind:
+ if (!value) return BB_INVALID;
+ char *script = strchr(value, ':');
+ if (!script) return BB_INVALID;
+ ++script;
+ int i;
+ for (i = 0; bindings[i].keys[0] > 0; i++) {
+ for (int j = 0; bindings[i].keys[j]; j++) {
+ if (bindings[i].keys[j] == *value) {
+ bindings[i].script = memcheck(strdup(script));
+ return BB_OK;
+ }
+ }
+ }
+ bindings[i].keys[0] = *value;
+ bindings[i].script = memcheck(strdup(script));
+ return BB_OK;
+ }
case 'c': { // +cd:, +columns:
switch (cmd[1]) {
case 'd': { // +cd:
@@ -1359,7 +1377,7 @@ void print_bindings(void)
char buf[1024];
char *kb = "Key Bindings";
printf("\n\033[33;1;4m\033[%dG%s\033[0m\n\n", (width-(int)strlen(kb))/2, kb);
- for (int i = 0; bindings[i].keys[0]; i++) {
+ for (int i = 0; bindings[i].keys[0] > 0; i++) {
char *p = buf;
for (int j = 0; bindings[i].keys[j]; j++) {
if (j > 0) *(p++) = ',';
diff --git a/config.def.h b/config.def.h
index 1468eec..a388410 100644
--- a/config.def.h
+++ b/config.def.h
@@ -250,7 +250,11 @@ binding_t bindings[] = {
{{KEY_CTRL_U}, "+scroll:-50%", B("Half page up")},
{{KEY_MOUSE_WHEEL_DOWN}, "+scroll:+3", B("Scroll down")},
{{KEY_MOUSE_WHEEL_UP}, "+scroll:-3", B("Scroll up")},
- {{0}}, // Array must be 0-terminated
+ // Leave some space for a few (16) runtime-defined key bindings:
+ {{0}}, {{0}}, {{0}}, {{0}}, {{0}}, {{0}}, {{0}}, {{0}},
+ {{0}}, {{0}}, {{0}}, {{0}}, {{0}}, {{0}}, {{0}}, {{0}},
+ {{-1}}
+ // Array must be -1-terminated
};
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1