def _add_str_to_rc_file()

in modular_cli/modular_cli_autocomplete/complete_handler.py [0:0]


def _add_str_to_rc_file(interpreter, script, admin_home_path,
                        installed_python_link):
    script_path = os.path.join(admin_home_path,
                               RELATIVE_PATH_TO_COMPLETE, script)
    source_string = f'\nsource {script_path} "{installed_python_link}" ' \
                    f'"{admin_home_path}"'
    rc_file_path = os.path.expanduser('~') + f'/.{interpreter}rc'
    with open(rc_file_path, 'r+') as f:
        if SHRC_AUTOCOMPLETE_MARKER not in f.read():
            f.write(f'\n# {SHRC_AUTOCOMPLETE_MARKER}')
            f.write(source_string)
            _LOG.info(f'Modular-CLI autocomplete have been '
                      f'successfully injected to the RC file. '
                      f'Path to the RC file: {rc_file_path}')
    return source_string