@@ -75,6 +75,33 @@ class BashKernel(Kernel):
|
||||
return {'status': 'ok', 'execution_count': self.execution_count,
|
||||
'payload': [], 'user_expressions': {}}
|
||||
|
||||
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 not code or code[-1] == ' ':
|
||||
return default
|
||||
|
||||
tokens = code.replace(';', ' ').split()
|
||||
if not tokens:
|
||||
return default
|
||||
|
||||
token = tokens[-1]
|
||||
start = cursor_pos - len(token)
|
||||
cmd = 'compgen -cdfa %s' % token
|
||||
output = self.bashwrapper.run_command(cmd).rstrip()
|
||||
|
||||
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'}
|
||||
|
||||
if __name__ == '__main__':
|
||||
from IPython.kernel.zmq.kernelapp import IPKernelApp
|
||||
IPKernelApp.launch_instance(kernel_class=BashKernel)
|
||||
|
||||
Reference in New Issue
Block a user