Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
output_stream = os.fdopen(8, "wb")
ifs = os.environ.get("_ARGCOMPLETE_IFS", "\v")
if len(ifs) != 1:
sys.exit(1)
current = os.environ["COMP_CUR"]
prev = os.environ["COMP_PREV"]
comp_line = os.environ["COMP_LINE"]
comp_point = int(os.environ["COMP_POINT"])
# Adjust comp_point for wide chars
if USING_PYTHON2:
comp_point = len(comp_line[:comp_point].decode(SYS_ENCODING))
else:
comp_point = len(comp_line.encode(SYS_ENCODING)[:comp_point].decode(SYS_ENCODING))
comp_line = ensure_str(comp_line)
comp_words = split_line(comp_line, comp_point)[3]
if "COMP_CWORD" in os.environ and os.environ["COMP_CWORD"] == "1":
keys = [x for x in list(COMMAND_MAPPINGS.keys()) if x.startswith(current)]
output_stream.write(ifs.join(keys).encode(SYS_ENCODING))
output_stream.flush()
sys.exit(0)
else:
command = prev
if len(comp_words) > 1:
command = comp_words[1]
if command not in COMMAND_MAPPINGS:
sys.exit(1)
command_type = COMMAND_MAPPINGS[command]
if command_type == "shell":
command = command + ".sh"
if command_type == "ndtshell":
if output_stream is None:
try:
output_stream = os.fdopen(8, "wb")
except IOError:
argcomplete.debug("Unable to open fd 8 for writing, quitting")
exit_method(1)
ifs = os.environ.get("_ARGCOMPLETE_IFS", "\013")
if len(ifs) != 1:
argcomplete.debug("Invalid value for IFS, quitting [{v}]".format(v=ifs))
exit_method(1)
comp_line = os.environ["COMP_LINE"]
comp_point = int(os.environ["COMP_POINT"])
comp_line = argcomplete.ensure_str(comp_line)
##############################
# SWAPPED FOR AUTOCOMPLETER
#
# Replaced with our own tokenizer function
##############################
tokens, _, begidx, endidx = tokens_for_completion(comp_line, comp_point)
# _ARGCOMPLETE is set by the shell script to tell us where comp_words
# should start, based on what we're completing.
# 1: