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

can't change editor via env vars #589

Open
caleb15 opened this issue Sep 7, 2020 · 9 comments
Open

can't change editor via env vars #589

caleb15 opened this issue Sep 7, 2020 · 9 comments

Comments

@caleb15
Copy link

caleb15 commented Sep 7, 2020

Thanks for submitting a bug report. Please provide the following information:

A description of the problem
I'm not able to change the editor cheat uses via env vars

cheat version info
4.0.4

(fifteen5) caleb•~/Documents/fifteen5(dev⚡)» EDITOR=code                                                                    [19:06:32]
(fifteen5) caleb•~/Documents/fifteen5(dev⚡)» cheat -e tree                                                                  [19:06:40]
failed to edit cheatsheet: exec: "vim": executable file not found in $PATH
(fifteen5) caleb•~/Documents/fifteen5(dev⚡)» export EDITOR=code                                                             [19:06:43]
(fifteen5) caleb•~/Documents/fifteen5(dev⚡)» cheat -e tree                                                                  [19:06:48]
failed to edit cheatsheet: exec: "vim": executable file not found in $PATH
(fifteen5) caleb•~/Documents/fifteen5(dev⚡)» export EDITOR=nano                                                             [19:06:50]
(fifteen5) caleb•~/Documents/fifteen5(dev⚡)» cheat -e tree                                                                  [19:07:15]
failed to edit cheatsheet: exec: "vim": executable file not found in $PATH
(fifteen5) caleb•~/Documents/fifteen5(dev⚡)» export VISUAL=code                                                             [19:07:17]
(fifteen5) caleb•~/Documents/fifteen5(dev⚡)» cheat -e tree                                                                  [19:07:45]
failed to edit cheatsheet: exec: "vim": executable file not found in $PATH
(fifteen5) caleb•~/Documents/fifteen5(dev⚡)» export VISUAL=nano                                                             [19:07:46]
(fifteen5) caleb•~/Documents/fifteen5(dev⚡)» cheat -e tree                                                                  [19:07:52]
failed to edit cheatsheet: exec: "vim": executable file not found in $PATH
(fifteen5) caleb•~/Documents/fifteen5(dev⚡)» export CHEAT_EDITOR=nano                                                       [19:07:54]
(fifteen5) caleb•~/Documents/fifteen5(dev⚡)» cheat -e tree                                                                  [19:09:17]
failed to edit cheatsheet: exec: "vim": executable file not found in $PATH
(fifteen5) caleb•~/Documents/fifteen5(dev⚡)» export CHEAT_EDITOR=code                                                       [19:09:19]
(fifteen5) caleb•~/Documents/fifteen5(dev⚡)» cheat -e tree                                                                  [19:09:23]
failed to edit cheatsheet: exec: "vim": executable file not found in $PATH

From the comment here it looks like it should be supported, or at least it used to be in the past.

As a workaround I was able to change the editor by changing ~/.config/cheat/conf.yml

@caleb15 caleb15 added the bug label Sep 7, 2020
@chrisallenlane
Copy link
Member

Hi, @caleb15

(fifteen5) caleb•~/Documents/fifteen5(dev⚡)» EDITOR=code [19:06:32]

It looks like you didn't export your envvar. Try:

export EDITOR=code

You can also do this all inline:

EDITOR=code cheat-e tree

Setting EDITOR is tedious to do this way, so you should consider adding the export to your .bashrc.

@caleb15
Copy link
Author

caleb15 commented Sep 9, 2020

@chrisallenlane I did export my env var, as you can see in the output I posted. I forgot to export the var the first time but remembered to do it later on, yet it still didn't work.

@chrisallenlane
Copy link
Member

Oh, I see. Sorry - I saw that first line and jumped to a conclusion.

A bit of experimentation on my machine suggests that this may in fact be broken. I'll take a look at it over the next few days, and will update this ticket when I have more information.

@chrisallenlane
Copy link
Member

OK - I see what's happening.

There's no "bug" here, in that this is working as intended. That said, I'm not sure that the way it's intended to work is actually sensible. Here's the relevant code:

	if conf.Editor == "" {
		if os.Getenv("VISUAL") != "" {
			conf.Editor = os.Getenv("VISUAL")
		} else if os.Getenv("EDITOR") != "" {
			conf.Editor = os.Getenv("EDITOR")
		} else {
			return Config{}, fmt.Errorf("no editor set")
		}
	}

The logic is that envvars will be respected if and only if you do not have an editor specified in your config file.

I'm not sure how I feel about this.

On one hand, it makes sense: it's necessary that you provide a config file, and it seems sensible that the values therein should be respected. I think an argument could be made that these envvars shouldn't be respected at all, and that it be required that all configs should be made via the config file.

On the other hand, given that envvars currently are respected, it's counter-intuitive that the following does not work:

EDITOR=nano cheat -e foo

(I personally expected the above to work, and was surprised when it did not.)

I guess that leaves us with a few options:

  1. Make envvars override config values
  2. Deprecate support for envvars entirely
  3. Do nothing, but make documentation surrounding this behavior clearer

I'm not sure which I prefer, personally, though 3 has the (significant) advantage of being backwards-compatible.

Do you have an opinion, @caleb15?

I'm going to leave this issue open for a while to gather input regarding how to proceed. In the meantime, yeah - set your editor in your config file, as you've already discovered 🙂

@Honeypot95
Copy link

Honeypot95 commented Jun 3, 2021

I have a similar enough problem. I installed cheat on Ubuntu via snap.

cheat -e does not respect the $EDITOR var, regardless of how I pass it. Either as above directly, either through my setting in .bashrc. It always defaults to vim, which seems to be what is happening to @caleb15 as well.

I verified with strace exactly what configuration it uses, and it has no editor set there (though it knows where vim and nano are).

I will try to investigate the problem myself, but I am a go novice, so not sure I can help much.

~ % cheat -v
4.2.1

@bernermic
Copy link
Contributor

Hey @Honeypot95 - the snap version has this config file: $HOME/snap/cheat/common/.config/cheat/conf.yml. Until this issue is solved please set your editor there.

Nano and vim are packaged together within the cheat snap, so these are the only two options to choose from. If you need a different editor you should install the cheat binary directly.

@tculp
Copy link
Contributor

tculp commented Oct 26, 2021

For the 3 options in @chrisallenlane 's comment, I would say making the envVar override the config option would make the most sense. $EDITOR is understood by many programs besides cheat, so it's something of an expected custom

@Ginner
Copy link

Ginner commented Nov 11, 2021

I'll just put in my 2 cents.

I disagree with @tculp - I think it should default to $EDITOR but an explicitly set editor in the conf file should overwrite this.

Furthermore, I think 'deprecating envvars' is not a nice way to go. Envvars is a pretty basic thing on a Linux system and should, in my opinion, be respected. In that vain, under cheatpaths in the config file envvars (like XDG_DATA_HOME) doesn't seem to be supported under path, which I find regrettable as well.

Thank you for a brilliant application!

@sullyj3
Copy link

sullyj3 commented Dec 23, 2021

I don't have a dog in the fight of whether the config should override EDITOR or vice versa.

I just installed cheat today. The thing that tripped me up was just that the generated config file sets the editor to vim. I had EDITOR set to nvim and no vim installed, so this was very confusing. Imo, the editor setting in the default conf.yml should be commented out. I think that would neatly sidestep this issue for newcomers.

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

No branches or pull requests

7 participants