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

config:edit examples using $EDITOR / $VISUAL with args don't work #1996

Open
edmorley opened this issue May 4, 2022 · 2 comments
Open

config:edit examples using $EDITOR / $VISUAL with args don't work #1996

edmorley opened this issue May 4, 2022 · 2 comments

Comments

@edmorley
Copy link
Member

edmorley commented May 4, 2022

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

The config:edit help text says:

DESCRIPTION
  This command opens the app config in a text editor set by $VISUAL or $EDITOR.
  Any variables added/removed/changed will be updated on the app after saving and closing the file.

EXAMPLES
  # edit with vim
  $ EDITOR="vim" heroku config:edit
  # edit with emacs
  $ EDITOR="emacs" heroku config:edit
  # edit with pico
  $ EDITOR="pico" heroku config:edit
  # edit with atom editor
  $ VISUAL="atom --wait" heroku config:edit

This works if I set EDITOR (or VISUAL) to a single command (such as code), however fails if I pass in additional arguments as per the final example in the help text.

$ EDITOR='code --wait' h config:edit
Fetching config... done
Waiting for code --wait... Error: spawn code --wait ENOENT

In VSCode's case, the argument --wait is required to make the editor wait for the window to be closed before the command returns (otherwise one gets a › Warning: no changes to config warning from the Heroku CLI, as the command returned early).

This is using macOS 12.3.1 with Homebrew bash.

What is the expected behavior?

That:

  • The examples reflect what works
  • It's possible to have EDITOR or VISUAL set to values that include arguments to commands.

This editor functionality is provided by the edit-string package, called here:

const s = await editor.edit(configToString(original), {prefix, postfix: '.sh'})

Whose implementation is here:
https://github.com/jdxcode/edit-string/blob/v1.1.6/src/edit.ts

@edmorley
Copy link
Member Author

edmorley commented May 4, 2022

I was hoping to work around this by eg creating a bash alias to wrap the --wait arg, however the edit-string package doesn't use the shell option with its execa usage, so that doesn't work.

However, a workaround that does work is to create a script that wraps the call and put that on PATH.

eg:

#!/usr/bin/env bash

exec code --wait "$@"

-> Ensure on path
-> export EDITOR='<script-name>.sh'

@machty
Copy link

machty commented Aug 2, 2022

I'm running into the same issue, in addition to a different one:

heroku-cli doesn't appear honor the EDITOR env var that I've set in my .zshrc:

machty@MacBook-Pro business-server % echo $EDITOR
/usr/bin/vim
machty@MacBook-Pro business-server % heroku config:edit -r staging

Running ^ this opens pico, not vim.

All of the following DO work though:

EDITOR=vim heroku config:edit -r staging
EDITOR=/usr/bin/vim heroku config:edit -r staging
EDITOR=$EDITOR heroku config:edit -r staging

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

No branches or pull requests

2 participants