summaryrefslogtreecommitdiff
path: root/src/actions.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/actions.c')
-rw-r--r--src/actions.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/actions.c b/src/actions.c
index 3fc733f..6adb8cf 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -81,6 +81,7 @@ static user_command user_commands[] =
{"restart", cmd_restart, arg_VOID},
{"startup_message", cmd_startup_message, arg_STRING},
{"link", cmd_link, arg_STRING},
+ {"alias", cmd_alias, arg_STRING},
/*@end (tag required for genrpbindings) */
/* Commands to set default behavior. */
@@ -115,6 +116,16 @@ static user_command user_commands[] =
#endif
{0, 0, 0} };
+struct cmd_alias
+{
+ char *name;
+ char *alias;
+};
+
+static struct cmd_alias *alias_list;
+static int alias_list_size;
+static int alias_list_last;
+
rp_action*
find_keybinding_by_action (char *action)
{
@@ -249,6 +260,11 @@ initialize_default_keybindings (void)
key_actions = (rp_action*) xmalloc (sizeof (rp_action) * key_actions_table_size);
key_actions_last = 0;
+ /* Initialive the alias list. */
+ alias_list_size = 5;
+ alias_list_last = 0;
+ alias_list = xmalloc (sizeof (cmd_alias) * alias_list_size);
+
prefix_key.sym = KEY_PREFIX;
prefix_key.state = MODIFIER_PREFIX;
@@ -827,6 +843,7 @@ command (int interactive, char *data)
char *cmd, *rest;
char *input;
user_command *uc;
+ int i;
if (data == NULL)
return NULL;
@@ -863,6 +880,16 @@ command (int interactive, char *data)
}
}
+ /* Look for it in the aliases. */
+ for (i=0; i<alias_list_last; i++)
+ {
+ if (!strcmp (cmd, alias_list[i].name))
+ {
+ result = command (interactive, alias_list[i].alias);
+ goto done;
+ }
+ }
+
marked_message_printf (0, 0, MESSAGE_UNKNOWN_COMMAND, cmd);
done:
@@ -2212,3 +2239,36 @@ cmd_defbarpadding (int interactive, void *data)
}
return NULL;
}
+
+char *
+cmd_alias (int interactive, void *data)
+{
+ char *name, *alias;
+
+ if (data == NULL)
+ {
+ message (" alias: At least one argument required ");
+ return NULL;
+ }
+
+ if (alias_list_last >= alias_list_size)
+ {
+ alias_list_size *= 2;
+ alias_list = xrealloc (alias_list, sizeof (cmd_alias) * alias_list_size);
+ }
+
+ name = strtok (data, " ");
+ alias = strtok (NULL, "\0");
+
+ if (name == NULL || alias == NULL)
+ {
+ message (" alias: Two arguments required ");
+ return NULL;
+ }
+
+ alias_list[alias_list_last].name = xstrdup (name);
+ alias_list[alias_list_last].alias = xstrdup (alias);
+ alias_list_last++;
+
+ return NULL;
+}