From 41bc603506cddf0edb74bd5f7f863ef88f6bddc5 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 31 Jul 2014 20:52:19 -0500 Subject: [PATCH] Fix possible IndexError and add whitespace --- bash_kernel.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bash_kernel.py b/bash_kernel.py index 2318e08..e514b4a 100644 --- a/bash_kernel.py +++ b/bash_kernel.py @@ -80,19 +80,24 @@ class BashKernel(Kernel): default = {'matches': [], 'cursor_start': 0, 'cursor_end': cursor_pos, 'metadata': dict(), 'status': 'ok'} - if code[-1] == ' ': + + if not code or code[-1] == ' ': return default + tokens = code.replace(';', ' ').split() if not tokens: return default + token = tokens[-1] start = cursor_pos - len(token) cmd = 'compgen -cdfa %s' % token output = self.bashwrapper.run_command(cmd).rstrip() + matches = output.split() if not matches: return default matches = [m for m in matches if m.startswith(token)] + return {'matches': matches, 'cursor_start': start, 'cursor_end': cursor_pos, 'metadata': dict(), 'status': 'ok'}