summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2011-10-16 15:58:00 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2011-10-16 15:58:00 +0100
commit11d519a7c3771c8a01ae45cb26803963d6bdb306 (patch)
tree7e13c5d87e7191361217ae83b2b71066e40bc7fb /alot
parentab194e7c0a763a71bba442a8871048bbf48cc185 (diff)
fix ! for shellescape and error handling
Diffstat (limited to 'alot')
-rw-r--r--alot/commands/__init__.py7
-rw-r--r--alot/commands/globals.py15
2 files changed, 13 insertions, 9 deletions
diff --git a/alot/commands/__init__.py b/alot/commands/__init__.py
index 5203daad..b374d317 100644
--- a/alot/commands/__init__.py
+++ b/alot/commands/__init__.py
@@ -89,6 +89,9 @@ def commandfactory(cmdline, mode='global'):
if not cmdline:
return None
logging.debug('mode:%s got commandline "%s"' % (mode, cmdline))
+ # allow to shellescape without a space after '!'
+ if cmdline.startswith('!'):
+ cmdline = 'shellescape \'%s\'' % cmdline[1:]
args = shlex.split(cmdline.encode('utf-8'))
args = map(lambda x: x.decode('utf-8'), args) # get unicode strings
logging.debug('ARGS: %s' % args)
@@ -99,10 +102,6 @@ def commandfactory(cmdline, mode='global'):
if alot.settings.config.has_option('command-aliases', cmdname):
cmdname = alot.settings.config.get('command-aliases', cmdname)
- # allow to shellescape without a space after '!'
- if cmdname.startswith('!'):
- argstring = cmdname[1:] + ' ' + argstring
- cmdname = 'shellescape'
# get class, argparser and forced parameter
(cmdclass, parser, forcedparms) = lookup_command(cmdname, mode)
diff --git a/alot/commands/globals.py b/alot/commands/globals.py
index fba07d93..0da6ba18 100644
--- a/alot/commands/globals.py
+++ b/alot/commands/globals.py
@@ -117,8 +117,11 @@ class ExternalCommand(Command):
callerbuffer = ui.current_buffer
def afterwards(data):
- if callable(self.on_success) and data == 'success':
- self.on_success()
+ if data == 'success':
+ if callable(self.on_success):
+ self.on_success()
+ else:
+ ui.notify(data, priority='error')
if self.refocus and callerbuffer in ui.buffers:
ui.logger.info('refocussing')
ui.buffer_focus(callerbuffer)
@@ -142,9 +145,11 @@ class ExternalCommand(Command):
cmd)
cmd = cmd.encode('utf-8', errors='ignore')
ui.logger.info('calling external command: %s' % cmd)
- returncode = subprocess.call(shlex.split(cmd))
- if returncode == 0:
- os.write(write_fd, 'success')
+ try:
+ if 0 == subprocess.call(shlex.split(cmd)):
+ os.write(write_fd, 'success')
+ except OSError, e:
+ os.write(write_fd, str(e))
if self.in_thread:
thread = threading.Thread(target=thread_code)