Skip to content

Instantly share code, notes, and snippets.

@devilholk
Last active November 17, 2020 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devilholk/b176b9c62c83636eb7552b3629e0b067 to your computer and use it in GitHub Desktop.
Save devilholk/b176b9c62c83636eb7552b3629e0b067 to your computer and use it in GitHub Desktop.
Example for bashcomp.sh
#!/usr/bin/python
import sys, os
#Usage: https://gist.github.com/devilholk/d1dcbb194086c84915c718d9ccafd95a
def combine_args(args):
result = list()
for a in args:
if result and result[-1].endswith('\\'):
result[-1] = result[-1][:-1] + ' ' + a
else:
result.append(a)
return result
#Get args
comp_line = combine_args(sys.argv[1:])
#Print debug info on remote terminal
from efforting.tech.remote_terminal import partial_update_remote_terminal
sys.stderr = partial_update_remote_terminal('localhost', 8885, f'Auxillary terminal for `{__file__}´', auto_clear=True)
print('ARGS', sys.argv, file=sys.stderr)
print('comp_line', comp_line, file=sys.stderr)
#Uggly test case - not a complete example
if comp_line == 'my_command show alias'.split():
print('compgen -a;')
elif comp_line == 'my_command show'.split():
print('echo alias;')
print('echo stuff;')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment