1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Automatically add/remove '/' when adding and removing aliases

This commit is contained in:
James Booth 2014-11-30 23:34:54 +00:00
parent e70cbd1b61
commit 8fee155797
2 changed files with 17 additions and 7 deletions

View File

@ -721,9 +721,9 @@ static struct cmd_t command_defs[] =
{ "/alias add|remove|list [name value]",
"-----------------------------------",
"Add, remove or show command aliases.",
"The alias will be available as a command",
"The alias will be available as a command, the leading '/' will be added if not supplied.",
"Example : /alias add friends /who online friends",
"Example : /alias add q /quit",
"Example : /alias add /q /quit",
"Example : /alias a /away \"I'm in a meeting.\"",
"Example : /alias remove q",
"Example : /alias list",

View File

@ -2795,8 +2795,15 @@ cmd_alias(gchar **args, struct cmd_help_t help)
cons_show("Usage: %s", help.usage);
return TRUE;
} else {
GString *ac_value = g_string_new("/");
g_string_append(ac_value, alias);
char *alias_p = alias;
GString *ac_value = g_string_new("");
if (alias[0] == '/') {
g_string_append(ac_value, alias);
alias_p = &alias[1];
} else {
g_string_append(ac_value, "/");
g_string_append(ac_value, alias);
}
char *value = args[2];
if (value == NULL) {
@ -2808,10 +2815,10 @@ cmd_alias(gchar **args, struct cmd_help_t help)
g_string_free(ac_value, TRUE);
return TRUE;
} else {
prefs_add_alias(alias, value);
prefs_add_alias(alias_p, value);
cmd_autocomplete_add(ac_value->str);
cmd_alias_add(alias);
cons_show("Command alias added /%s -> %s", alias, value);
cmd_alias_add(alias_p);
cons_show("Command alias added %s -> %s", ac_value->str, value);
g_string_free(ac_value, TRUE);
return TRUE;
}
@ -2822,6 +2829,9 @@ cmd_alias(gchar **args, struct cmd_help_t help)
cons_show("Usage: %s", help.usage);
return TRUE;
} else {
if (alias[0] == '/') {
alias = &alias[1];
}
gboolean removed = prefs_remove_alias(alias);
if (!removed) {
cons_show("No such command alias /%s", alias);