def register_file(system): rc_files = get_rc_files(system) for file in rc_files: print(f"registering {file}") append_to_file(file, "# CLAI setup\n") append_to_file(file, 'if ! [ ${#preexec_functions[@]} -eq 0 ]; then\n') append_to_file(file, ' if ! [[ " ${preexec_functions[@]} " =~ " preexec_override_invoke " ]]; then\n') append_to_file(file, f" source {get_setup_file()} \n") append_to_file(file, ' fi\n') append_to_file(file, 'else\n') append_to_file(file, f" source {get_setup_file()} \n") append_to_file(file, 'fi\n') append_to_file(file, "# End CLAI setup\n")
def register_file(system): rc_files = get_rc_files(system) for file in rc_files: encoding = "utf-8" newline = "\n" left_bracket = "[" right_bracket = "]" # The open() with encoding cp1047 (IBM-1047) doesn't work well or works # as cp037 (IBM-037) if is_rw_with_EBCDIC(file): encoding = "cp1047" left_bracket = "\xDD" right_bracket = "\xA8" # newline must be '\x85' when using IzODA and Rocket Pythons, but # '\n' when using IBM Python. Since we can only easily support one # path at the moment, we're going to support IBM Python since it # works better. This code is only needed to run when .bashrc and/or # .bash_profile is untagged; if the files are already tagged ASCII # or EBCDIC, then everything works fine on both IzODA/Rocket IBM # Pythons. We will document this in known-issues.md and call it # a day. #newline = "\x85" print(f"registering {file}") append_to_file(file, "# CLAI setup" + newline, encoding) append_to_file( file, 'if ! ' + left_bracket + ' ${#preexec_functions' + left_bracket + '@' + right_bracket + '} -eq 0 ' + right_bracket + '; then' + newline, encoding) append_to_file( file, ' if ! ' + left_bracket + left_bracket + ' " ${preexec_functions' + left_bracket + '@' + right_bracket + '} " =~ " preexec_override_invoke " ' + right_bracket + right_bracket + '; then' + newline, encoding) append_to_file(file, f" source {get_setup_file()} " + newline, encoding) append_to_file(file, ' fi' + newline, encoding) append_to_file(file, 'else' + newline, encoding) append_to_file(file, f" source {get_setup_file()} " + newline, encoding) append_to_file(file, 'fi' + newline, encoding) append_to_file(file, "# End CLAI setup" + newline, encoding)
def remove_setup_register(): rc_files = get_rc_files() for file in rc_files: remove_lines_setup(file)