diff --git a/bash_kernel.py b/bash_kernel.py index c8b63e0..2318e08 100644 --- a/bash_kernel.py +++ b/bash_kernel.py @@ -77,19 +77,23 @@ class BashKernel(Kernel): def do_complete(self, code, cursor_pos): code = code[:cursor_pos] + default = {'matches': [], 'cursor_start': 0, + 'cursor_end': cursor_pos, 'metadata': dict(), + 'status': 'ok'} if code[-1] == ' ': - return + return default tokens = code.replace(';', ' ').split() if not tokens: - return + return default token = tokens[-1] - # check for valid function name - if not re.match('\A[a-zA-Z_]', token): - return start = cursor_pos - len(token) - cmd = 'compgen -c %s' % token + cmd = 'compgen -cdfa %s' % token output = self.bashwrapper.run_command(cmd).rstrip() - return {'matches': output.split(), 'cursor_start': start, + 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'}