Open files in the user's editor.
(self, filenames: cabc.Iterable[str])
| 684 | return "vi" |
| 685 | |
| 686 | def edit_files(self, filenames: cabc.Iterable[str]) -> None: |
| 687 | """Open files in the user's editor.""" |
| 688 | import shlex |
| 689 | import subprocess |
| 690 | |
| 691 | editor = self.get_editor() |
| 692 | environ: dict[str, str] | None = None |
| 693 | |
| 694 | if self.env: |
| 695 | environ = os.environ.copy() |
| 696 | environ.update(self.env) |
| 697 | |
| 698 | try: |
| 699 | # Split in POSIX mode (the default) for the same reasons as |
| 700 | # in pager(): strips quotes from tokens and preserves quoted |
| 701 | # Windows paths. |
| 702 | c = subprocess.Popen( |
| 703 | args=shlex.split(editor) + list(filenames), |
| 704 | env=environ, |
| 705 | ) |
| 706 | exit_code = c.wait() |
| 707 | if exit_code != 0: |
| 708 | raise ClickException( |
| 709 | _("{editor}: Editing failed").format(editor=editor) |
| 710 | ) |
| 711 | except OSError as e: |
| 712 | raise ClickException( |
| 713 | _("{editor}: Editing failed: {e}").format(editor=editor, e=e) |
| 714 | ) from e |
| 715 | |
| 716 | @t.overload |
| 717 | def edit(self, text: bytes | bytearray) -> bytes | None: ... |