| 522 | |
| 523 | |
| 524 | def shell_configure(args, compat): |
| 525 | global CONST_shell_profile, CONST_shell_config |
| 526 | |
| 527 | source_string = '\n. "{0}"\n'.format(join(args.path, "env")) |
| 528 | |
| 529 | if ("bash" in SHELL) or ("zsh" in SHELL): |
| 530 | CONST_shell_config = join(HOME, "." + SHELL + "rc") |
| 531 | |
| 532 | if "zsh" in SHELL: |
| 533 | CONST_shell_profile = join(HOME, "." + "zshenv") |
| 534 | else: |
| 535 | CONST_shell_profile = join(HOME, "." + SHELL + "_profile") |
| 536 | |
| 537 | if not exists(CONST_shell_config) and compat.platform != "Darwin": |
| 538 | open(CONST_shell_config, "a").close() |
| 539 | |
| 540 | write_shell = False |
| 541 | if compat.platform != "Darwin": |
| 542 | with opened_w_error(CONST_shell_config, "r") as shell_config: |
| 543 | if shell_config is not None: |
| 544 | if source_string not in shell_config.read(): |
| 545 | write_shell = True |
| 546 | else: |
| 547 | write_shell = True |
| 548 | |
| 549 | # On Darwin: Append to shell config only if shell_profile does not exist |
| 550 | # On Linux: Append to shell config anyway |
| 551 | if write_shell and compat.platform != "Darwin": |
| 552 | with opened_w_error(CONST_shell_config, "a") as shell_config: |
| 553 | if shell_config is not None: |
| 554 | shell_config.write(source_string) |
| 555 | write_shell = False |
| 556 | |
| 557 | if exists(CONST_shell_profile): |
| 558 | with opened_w_error(CONST_shell_profile, "r") as shell_profile: |
| 559 | if shell_profile is not None: |
| 560 | if source_string not in shell_profile.read(): |
| 561 | write_shell = True |
| 562 | if write_shell: |
| 563 | with opened_w_error(CONST_shell_profile, "a") as shell_profile: |
| 564 | if shell_profile is not None: |
| 565 | shell_profile.write(source_string) |
| 566 | write_shell = False |
| 567 | elif compat.platform == "Darwin" and "zsh" in SHELL: |
| 568 | open(CONST_shell_profile, "a").close() |
| 569 | with opened_w_error(CONST_shell_profile, "r") as shell_config: |
| 570 | if shell_config is not None: |
| 571 | if source_string not in shell_config.read(): |
| 572 | write_shell = True |
| 573 | else: |
| 574 | write_shell = True |
| 575 | if write_shell: |
| 576 | with opened_w_error(CONST_shell_profile, "a") as shell_profile: |
| 577 | if shell_profile is not None: |
| 578 | shell_profile.write(source_string) |
| 579 | write_shell = False |
| 580 | |
| 581 | else: |