diff options
author | Justus Winter <4winter@informatik.uni-hamburg.de> | 2011-09-22 11:54:08 +0200 |
---|---|---|
committer | Justus Winter <4winter@informatik.uni-hamburg.de> | 2011-09-22 14:31:08 +0200 |
commit | 7aa14cee565777939411e70508c73f8688e9dbac (patch) | |
tree | 5b53e4db38931500b5cf3e563e3465df0b55da06 /alot | |
parent | 4c33283363606079f2cd27a376d2fd012b157f76 (diff) |
Enhance external command templates
Allow find style ('{}') command templates in the external
command and securely quote the filename one has been given.
Diffstat (limited to 'alot')
-rw-r--r-- | alot/command.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/alot/command.py b/alot/command.py index d719ca81..046b50db 100644 --- a/alot/command.py +++ b/alot/command.py @@ -140,11 +140,13 @@ class RefreshCommand(Command): class ExternalCommand(Command): """calls external command""" - def __init__(self, commandstring, spawn=False, refocus=True, + def __init__(self, commandstring, path=None, spawn=False, refocus=True, in_thread=False, on_success=None, **kwargs): """ :param commandstring: the command to call :type commandstring: str + :param path: a path to a file (or None) + :type path: str :param spawn: run command in a new terminal :type spawn: boolean :param in_thread: run asynchronously, don't block alot @@ -155,6 +157,7 @@ class ExternalCommand(Command): :type on_success: callable """ self.commandstring = commandstring + self.path = path self.spawn = spawn self.refocus = refocus self.in_thread = in_thread @@ -174,7 +177,14 @@ class ExternalCommand(Command): write_fd = ui.mainloop.watch_pipe(afterwards) def thread_code(*args): - cmd = self.commandstring + if self.path: + if '{}' in self.commandstring: + cmd = self.commandstring.replace('{}', helper.shell_quote(self.path)) + else: + cmd = '%s %s' % (self.commandstring, helper.shell_quote(self.path)) + else: + cmd = self.commandstring + if self.spawn: cmd = '%s %s' % (settings.config.get('general', 'terminal_cmd'), @@ -202,8 +212,8 @@ class EditCommand(ExternalCommand): else: self.spawn = settings.config.getboolean('general', 'spawn_editor') editor_cmd = settings.config.get('general', 'editor_cmd') - cmd = editor_cmd + ' ' + self.path - ExternalCommand.__init__(self, cmd, spawn=self.spawn, + + ExternalCommand.__init__(self, editor_cmd, path=self.path, spawn=self.spawn, in_thread=self.spawn, **kwargs) |