about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-11-30 23:34:54 +0000
committerJames Booth <boothj5@gmail.com>2014-11-30 23:34:54 +0000
commit8fee15579765d27aedbcdcd0cc418a6627de2353 (patch)
tree5324bbd145f7657c4f203a65aadd10b96a918e5e /src/command
parente70cbd1b618d35e441cd412649651ea6b8cd97e3 (diff)
downloadprofani-tty-8fee15579765d27aedbcdcd0cc418a6627de2353.tar.gz
Automatically add/remove '/' when adding and removing aliases
Diffstat (limited to 'src/command')
-rw-r--r--src/command/command.c4
-rw-r--r--src/command/commands.c20
2 files changed, 17 insertions, 7 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 6c52af2a..9abc4cf3 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -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",
diff --git a/src/command/commands.c b/src/command/commands.c
index fc95f521..214c8069 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -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);