Skip to content
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

Support editors with arguments, using shlex #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

davidparsson
Copy link

Fixes #11.

@fmoo
Copy link
Owner

fmoo commented Oct 16, 2017 via email

@davidparsson
Copy link
Author

@fmoo, is editors with (unescaped) spaces a thing that need to be supported? I don't think it should be, at least not on *nix.

Even Bash's CTRL+x, CTRL+e does not support EDITOR='some editor', but supports EDITOR='some\ editor'. The same goes for git. Or are there other cases where it makes sense to support this?

@eugene-eeo
Copy link
Contributor

What about:

def edit(filename=None, args=(), contents=None, use_tty=None):
    editor = get_editor()
    args = [editor] + (args or get_editor_args(...))
    ...

We assume that if you're gonna pass in additional arguments args then you know what you're doing. This solves issues such as "Where do the additional arguments go".

@davidparsson davidparsson changed the title Support editors with spaces with shlex Support editors with arguments, using shlex Oct 19, 2017
@davidparsson
Copy link
Author

davidparsson commented Oct 19, 2017

Okay, let's make sure we don't misunderstand each other, because I see that #11 may be misinterpreted. When I opened #11 I did not mean to add support for binaries with spaces in their names, but to allow passing arguments in the $EDITOR variable. This conforms with how the $EDITOR variable is handled by other tools I've used, and has the (intentional) side-effect of breaking editors with (unescaped) spaces in their names.

But if you're still convinced that support for both cases are needed, despite it not being the "standard way", please let me know.

@eugene-eeo
Copy link
Contributor

eugene-eeo commented Oct 19, 2017

Ok that makes a ton of sense now. 👍 My bad for rushing into it; can you verify the behaviour of most tools when we pass in arguments to the $EDITOR variable? I.e. are there any additional arguments passed? Thanks.

@davidparsson
Copy link
Author

Apart from bash and git (above), a few Googles found this:

Bash, git and emacs are all pretty prominent software projects, but apart from that, if you're not convinced, I'm not really sure what more tools to test. What else uses $EDITOR?

@fmoo
Copy link
Owner

fmoo commented Oct 19, 2017 via email

@davidparsson
Copy link
Author

I'm not sure what all current default arguments for all editors do, but I'm a big fan of sane defaults, so I think the augment approach seems like a reasonable way to go. Do you know how hg handles this case? Is it likely that any user would want to remove those default arguments?

I fully agree about the major version bump as well

@josh-gree
Copy link
Contributor

josh-gree commented Apr 23, 2019

Hi any updates on this issue? Would like to be able to open vscode which requires -w -n as args. Currently just hacked this by adding code with those args to the get_editor_args function...

    elif editor == "code":
        return ["-w", "-n"]

Don't really want to create a fork just to support this...

@davidparsson
Copy link
Author

davidparsson commented Apr 23, 2019

@josh-gree, my workaround for this was to create a scripts that opens the editor with arguments.

My /usr/bin/editor could contain something like:

#!/bin/sh
code -w -n $1

and then I've set $EDITOR to /usr/bin/editor.

Disclaimer: I've not tested this example, but you probably get it.

@fmoo
Copy link
Owner

fmoo commented Apr 23, 2019

@josh-gree if you put up a PR for get_editor_args defaults update for vscode, I'll take it.

@fmoo
Copy link
Owner

fmoo commented Apr 23, 2019

(I'd do a quick release as 1.0.4 and then look at pulling this change in as 2.0)

@josh-gree
Copy link
Contributor

josh-gree commented May 3, 2019

@fmoo PR added #26

@23Skidoo
Copy link

Any news on the 2.0 release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Having an $EDITOR with arguments raises an exception
5 participants