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