8000 Support for editing multiple files using `click.edit` · Issue #2067 · pallets/click · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support for editing multiple files using click.edit #2067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yashrathi-git opened this issue Sep 14, 2021 · 0 comments
Closed

Support for editing multiple files using click.edit #2067

yashrathi-git opened this issue Sep 14, 2021 · 0 comments
Milestone

Comments

@yashrathi-git
Copy link
Contributor

Hello,

Most of the editors(like nano, vim, vi, vscode etc) have support for multiple tabs. The only editor that I can recall that don't support multiple tabs is notepad. Something like this could be really helpful and also could be easily implemented into click:

import click
click.edit(filenames = {'path/to/file1', 'path/to/file2'})

Instead of calling editor using single file as argument it provides multiple files as arguments here.

So it calls something like:

vim "/path/to/file/1" "/path/to/file/2"

All editors don't support tabs, but most of them do.

Right now implementing something like this without changes to click would look like:

from click._termui_impl import Editor

class CustomEditor(Editor):
    def edit_multiple(self, filenames: Sequence[str]):
        import subprocess

        editor = self.get_editor()
        filenames = ' '.join(f'"{name}"' for name in filenames)
        try:
            c = subprocess.Popen(f'{editor} {filenames}', shell=True)
            exit_code = c.wait()
            if exit_code != 0:
                raise click.ClickException(
                    "{editor}: Editing failed".format(editor=editor)
                )

        except OSError as e:
            raise click.ClickException(
                "{editor}: Editing failed: {e}".format(editor=editor, e=e)
            )


def edit_multiple(filenames: Sequence[str], editor: Optional[str] = None):
    ed = CustomEditor(editor=editor)
    ed.edit_multiple(filenames)

This looks really bad because we have to import from protected file and there is a lot of repetitive code.

Thank you

@yashrathi-git yashrathi-git changed the title Support to open multiple files in text-editor using click.edit Support for editing multiple files using click.edit Sep 14, 2021
@AndreasBackx AndreasBackx added this to the 8.2.0 milestone Jan 12, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0