Merge tab completion improvements from @herr-biber

main
Thomas Kluyver 10 years ago
commit 6ddaaed59a

@ -122,17 +122,28 @@ class BashKernel(Kernel):
if not tokens: if not tokens:
return default return default
matches = []
token = tokens[-1] token = tokens[-1]
start = cursor_pos - len(token) start = cursor_pos - len(token)
cmd = 'compgen -cdfa %s' % token
output = self.bashwrapper.run_command(cmd).rstrip()
matches = output.split() if token[0] == '$':
# complete variables
cmd = 'compgen -A arrayvar -A export -A variable %s' % token[1:] # strip leading $
output = self.bashwrapper.run_command(cmd).rstrip()
completions = set(output.split())
# append matches including leading $
matches.extend(['$'+c for c in completions])
else:
# complete functions and builtins
cmd = 'compgen -cdfa %s' % token
output = self.bashwrapper.run_command(cmd).rstrip()
matches.extend(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': sorted(matches), 'cursor_start': start,
'cursor_end': cursor_pos, 'metadata': dict(), 'cursor_end': cursor_pos, 'metadata': dict(),
'status': 'ok'} 'status': 'ok'}

Loading…
Cancel
Save