summaryrefslogtreecommitdiff
path: root/plugins/alias.py
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-11-09 01:23:35 +0100
committerFlorent Le Coz <louiz@louiz.org>2011-11-09 01:23:35 +0100
commitad0b3b41ecc0003f3d5b4fdb9799b6e325127e1f (patch)
tree3f2bbf1be7f753f1c7495f0a60833f469e7f10a7 /plugins/alias.py
parent7fadb35fe2e7932a0a4aa6a8184ab6b186669edc (diff)
parent03999f1ef08036b7ea25e2239cf7b6bcdb4d76cc (diff)
downloadpoezio-ad0b3b41ecc0003f3d5b4fdb9799b6e325127e1f.tar.gz
poezio-ad0b3b41ecc0003f3d5b4fdb9799b6e325127e1f.tar.bz2
poezio-ad0b3b41ecc0003f3d5b4fdb9799b6e325127e1f.tar.xz
poezio-ad0b3b41ecc0003f3d5b4fdb9799b6e325127e1f.zip
Merge branch 'plugins'
Conflicts: README src/core.py src/tabs.py
Diffstat (limited to 'plugins/alias.py')
-rw-r--r--plugins/alias.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/plugins/alias.py b/plugins/alias.py
new file mode 100644
index 00000000..eb596332
--- /dev/null
+++ b/plugins/alias.py
@@ -0,0 +1,40 @@
+from plugin import BasePlugin
+
+class Plugin(BasePlugin):
+ def init(self):
+ self.add_command('alias', self.command_alias, '/alias <alias> <command> <args>\nAlias: create an alias command')
+ self.add_command('unalias', self.command_unalias, '/unalias <alias>\nUnalias: remove a previously created alias')
+ self.commands = {}
+
+ def command_alias(self, line):
+ arg = line.split()
+ if len(arg) < 2:
+ self.core.information('Alias: Not enough parameters', 'Error')
+ return
+ alias = arg[0]
+ command = arg[1]
+ post_args = ' '.join(arg[2:])
+
+ if alias in self.core.commands or alias in self.commands:
+ self.core.information('Alias: command already exists', 'Error')
+ return
+ self.commands[alias] = lambda args: self.get_command(command)(post_args+args)
+ self.add_command(alias, self.commands[alias], 'This command is an alias for /%s %s' % (command, post_args))
+ self.core.information('Alias /%s successfuly created' % alias, 'Info')
+
+ def command_unalias(self, alias):
+ if alias in self.commands:
+ del self.commands[alias]
+ self.del_command(alias)
+ self.core.information('Alias /%s successfuly deleted' % alias, 'Info')
+
+ def get_command(self, name):
+ """Returns the function associated with a command"""
+ def dummy(args):
+ """Dummy function called if the command doesn’t exist"""
+ pass
+ if name in self.core.commands:
+ return self.core.commands[name][0]
+ elif name in self.core.current_tab().commands:
+ return self.core.current_tab().commands[name][0]
+ return dummy