#!/usr/libexec/python3.13
# Shell completion helper for the AWS CLI v2 with bundled dependencies
import os
import sys

# AWSCLI2_LIBDIR exists so that the package %check section can run the
# launcher from the buildroot before the files are installed
sys.path.insert(0, os.environ.get("AWSCLI2_LIBDIR", "/usr/libexec/awscli2/lib"))

if os.environ.get('LC_CTYPE', '') == 'UTF-8':
    os.environ['LC_CTYPE'] = 'en_US.UTF-8'

from awscli.autocomplete.main import autocomplete

# bash exports COMP_LINE and COMP_POINT, tcsh COMMAND_LINE only
command_line = (
    os.environ.get('COMP_LINE') or os.environ.get('COMMAND_LINE') or ''
)
command_index = int(os.environ.get('COMP_POINT') or len(command_line))

try:
    autocomplete(command_line, command_index)
except KeyboardInterrupt:
    # If the user hits Ctrl+C, we don't want to print a traceback.
    pass
