The following commit: 9385e182, added an & at the end of the drush conf command:

return drush_shell_exec_interactive('$EDITOR %s &', $all[$choice]);

which makes the call to $EDITOR a background process. But this doesn't work if your editor is vim and you run it in a terminal or if you are ssh'd into a server, and you try to use drush conf to open config files.

I get the following error when I ssh into a server and run drush conf:
emacs: standard input is not a tty

Is there a way to tell if the editor of choice needs to run in the terminal as a foreground process and not append the & in that case?

Thanks,
Bart

Comments

greg.1.anderson’s picture

I was working on adjusting my bash configuration files to set EDITOR to a GUI editor when running from an X session, and set it to vi or vim when running via ssh. At the moment, I am looking at the DISPLAY environment variable to determine this; using this technique means that you get your GUI editor when ssh'ed in with an X-tunnel, which may or may not be what you want.

Maybe Drush should do something similar, and use EDITOR with '&' when in GUI mode, and use CONSOLE_EDITOR without '&' when in console mode.

greg.1.anderson’s picture

I am wondering if perhaps 9385e182 should be backed out for now. This is a very recent change; it is unknown at this point how many people it will impact negatively. The GUI editor I use returns control to the commandline immediately when it is called; while this is not universal behavior, it is common. So, not everyone is helped by the '&', and some are inconvenienced by it. Perhaps a short-term compromise would be to add a 'background' flag to drush conf, so that those who need it may request it.

moshe weitzman’s picture

That commit is almost exactly a year old. Mind your years!

Anyway, I don't recall why I wanted it. Moving to an option for the '&' works for me. I have no opinion on the default for that option.

bartlantz’s picture

Status: Active » Needs review
StatusFileSize
new2.43 KB

Here's a patch that adds an option "--background" to drush config. When it's set, it will open the editor as a background process, otherwise it opens the editor in the foreground.

greg.1.anderson’s picture

Status: Needs review » Needs work

Drush-5 has shipped with background as the default behavior for drush conf. If we add a flag at this point, the default will need to be in the background to avoid changing existing behavior.

bartlantz’s picture

That makes complete sense! I didn't think about that. Here's the patch updated so that it defaults to opening the editor in the background, and if the user passes in the --foreground option, it calls the $EDITOR without the ampersand.

Thanks,
Bart

bartlantz’s picture

Status: Needs work » Needs review

Forgot to switch status to needs review.

joestewart’s picture

patch applied fine. The patch and the --foreground switch worked for me with vim and nano. And failed without.

I tried a bunch of other editors that all returned back to the shell prompt without issue.

greg.1.anderson’s picture

Status: Needs review » Fixed

A variant of this was committed a while back; somehow we reversed on #5 and made foreground the default. That is probably the best behavior, and just a small hit on backwards compatibility.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.