From 5a3d3b795ccdae5df700e2ee8042b138a088fb23 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 31 Jul 2014 20:02:50 -0500 Subject: [PATCH] Allow completions to work for files, directories, and aliases. --- bash_kernel.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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'}