Fix possible IndexError and add whitespace

main
Steven Silvester 12 years ago
parent 5a3d3b795c
commit 41bc603506

@ -80,19 +80,24 @@ class BashKernel(Kernel):
default = {'matches': [], 'cursor_start': 0, default = {'matches': [], 'cursor_start': 0,
'cursor_end': cursor_pos, 'metadata': dict(), 'cursor_end': cursor_pos, 'metadata': dict(),
'status': 'ok'} 'status': 'ok'}
if code[-1] == ' ':
if not code or code[-1] == ' ':
return default return default
tokens = code.replace(';', ' ').split() tokens = code.replace(';', ' ').split()
if not tokens: if not tokens:
return default return default
token = tokens[-1] token = tokens[-1]
start = cursor_pos - len(token) start = cursor_pos - len(token)
cmd = 'compgen -cdfa %s' % token cmd = 'compgen -cdfa %s' % token
output = self.bashwrapper.run_command(cmd).rstrip() output = self.bashwrapper.run_command(cmd).rstrip()
matches = output.split() matches = output.split()
if not matches: if not matches:
return default return default
matches = [m for m in matches if m.startswith(token)] matches = [m for m in matches if m.startswith(token)]
return {'matches': matches, 'cursor_start': start, return {'matches': matches, 'cursor_start': start,
'cursor_end': cursor_pos, 'metadata': dict(), 'cursor_end': cursor_pos, 'metadata': dict(),
'status': 'ok'} 'status': 'ok'}

Loading…
Cancel
Save