summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2014-04-22 20:21:00 +0200
committermathieui <mathieui@mathieui.net>2014-04-22 20:21:00 +0200
commit2b63e76ef9459dc0d016f58ade6526504f458683 (patch)
treee35e14bedf4df848cced1b28bd9cb7f2df60d55d /plugins
parente6ce1ce7b6f45f119015f03185212317a7c20fc6 (diff)
downloadpoezio-2b63e76ef9459dc0d016f58ade6526504f458683.tar.gz
poezio-2b63e76ef9459dc0d016f58ade6526504f458683.tar.bz2
poezio-2b63e76ef9459dc0d016f58ade6526504f458683.tar.xz
poezio-2b63e76ef9459dc0d016f58ade6526504f458683.zip
Update the alias plugin
- use the new PluginConfig.remove method to remove aliases - do not do weird stuff when no args are provided - do not flood when re-creating stored aliases
Diffstat (limited to 'plugins')
-rw-r--r--plugins/alias.py38
1 files changed, 24 insertions, 14 deletions
diff --git a/plugins/alias.py b/plugins/alias.py
index 490605e5..fc482f22 100644
--- a/plugins/alias.py
+++ b/plugins/alias.py
@@ -92,35 +92,42 @@ class Plugin(BasePlugin):
for alias in self.config.options():
full = self.config.get(alias, '')
if full:
- self.command_alias(alias + ' ' + full)
+ self.command_alias(alias + ' ' + full, silent=True)
- def command_alias(self, line):
+ def command_alias(self, line, silent=False):
"""
/alias <alias> <command> [args]
"""
arg = split_args(line)
if not arg:
- self.api.information('Alias: Not enough parameters', 'Error')
+ if not silent:
+ self.api.information('Alias: Not enough parameters', 'Error')
return
alias, command, args = arg
if alias in self.commands:
update = True
elif alias in self.core.commands:
- self.api.information('Alias: command already exists', 'Error')
+ if not silent:
+ self.api.information('Alias: command already exists', 'Error')
return
else:
update = False
self.config.set(alias, command + ' ' + args)
- self.commands[alias] = command_wrapper(generic_command, lambda: self.get_command(command), args)
+ self.commands[alias] = command_wrapper(
+ generic_command, lambda: self.get_command(command), args)
self.api.del_command(alias)
- self.api.add_command(alias, self.commands[alias], 'This command is an alias for /%s %s' %(alias, command))
+ self.api.add_command(alias, self.commands[alias],
+ 'This command is an alias for /%s %s' %
+ (alias, command))
- if update:
- self.api.information('Alias /%s updated' % alias, 'Info')
- else:
- self.api.information('Alias /%s successfuly created' % alias, 'Info')
+ if not silent:
+ if update:
+ self.api.information('Alias /%s updated' % alias, 'Info')
+ else:
+ self.api.information('Alias /%s successfuly created' % alias,
+ 'Info')
def command_unalias(self, alias):
"""
@@ -129,8 +136,7 @@ class Plugin(BasePlugin):
if alias in self.commands:
del self.commands[alias]
self.api.del_command(alias)
- self.config.set(alias, '')
- self.config.write()
+ self.config.remove(alias)
self.api.information('Alias /%s successfuly deleted' % alias, 'Info')
def completion_unalias(self, the_input):
@@ -161,8 +167,12 @@ def split_args(line):
alias = line[:alias_pos]
end = line[alias_pos+1:]
args_pos = end.find(' ')
- command = end[:args_pos]
- args = end[args_pos+1:]
+ if args_pos == -1:
+ command = end
+ args = ''
+ else:
+ command = end[:args_pos]
+ args = end[args_pos+1:]
return (alias, command, args)
def generic_command(command, extra_args, args):