cheat icon indicating copy to clipboard operation
cheat copied to clipboard

can't change editor via env vars

Open caleb15 opened this issue 5 years ago • 9 comments

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 avatar Sep 07 '20 02:09 caleb15

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.

chrisallenlane avatar Sep 07 '20 10:09 chrisallenlane

@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.

caleb15 avatar Sep 09 '20 20:09 caleb15

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 avatar Sep 10 '20 12:09 chrisallenlane

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 :slightly_smiling_face:

chrisallenlane avatar Sep 12 '20 12:09 chrisallenlane

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

Honeypot95 avatar Jun 03 '21 10:06 Honeypot95

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.

bernermic avatar Jun 03 '21 14:06 bernermic

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

tculp avatar Oct 26 '21 03:10 tculp

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!

Ginner avatar Nov 11 '21 13:11 Ginner

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.

sullyj3 avatar Dec 23 '21 00:12 sullyj3