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

SOPS errors out if the value of the EDITOR environment variable contains spaces. #778

Closed
akunaatrium opened this issue Dec 2, 2020 · 7 comments

Comments

@akunaatrium
Copy link

In Windows 10, using PowerShell 5.1 when setting the environment variable EDITOR as follows:

$env:EDITOR = 'C:\Program Files (x86)\Notepad++\notepad++.exe'

And trying to edit a file using sops like this:

sops.exe .\file.enc.yaml

The following error message is returned:

Could not run editor: exec: "C:Program": file does not exist

Expected behavior would be that the editor is opened up.

Is there any workaround or solution to this (didn't try a path without spaces and don't consider that as a viable workaround anyway).

@akunaatrium
Copy link
Author

Discovered that one can use the legacy file name convention to describe file and folder names longer than 8 characters, like this:

$env:EDITOR = 'C:/Progra~2/Notepad++/notepad++.exe'

Notice the forward slashes as well. SOPS doesn't seem to support backslashes in the path.

@akunaatrium
Copy link
Author

Notepad++ runs asynchronously by default, so basically if one chooses to use Notepad++ as the editor, as soon as sops opens up Notepad++, sops exits and says "File has not changed, exiting.". Just as a reference for people stumbling upon this problem, to make Notepad++ run synchronously, give the -multiInst -nosession -notabbar flags to the executable. Thus, setting the environment variable becomes:

$env:EDITOR = 'C:/Progra~2/Notepad++/notepad++.exe -multiInst -nosession -notabbar'

Haven't tried to set a permanent system wide environment variable yet but I suppose it works there as well.

@autrilla
Copy link
Contributor

autrilla commented Dec 2, 2020

This is because we use shlex when parsing the $EDITOR:

https://github.com/mozilla/sops/blob/38b25bd449619e1d6da20e637702f7c73203aa44/cmd/sops/edit.go#L260

We have to way of knowing if the thing after the space is an argument or a path with a space. Have you tried quoting the path?

@akunaatrium
Copy link
Author

akunaatrium commented Dec 2, 2020 via email

@akunaatrium
Copy link
Author

Or today. Looks like setting the path this way makes it work:

$env:EDITOR = "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -nosession -notabbar"

Case solved, thanks!

@autrilla autrilla closed this as completed Dec 2, 2020
@patricknelson
Copy link

patricknelson commented Dec 19, 2020

In case anyone wants an alternative, I discovered this worked with the full Windows path using backslashes as well (this is the stored unescaped value):

"C:\\Program Files\\Notepad++\\notepad++.exe"

What's odd is that it's already in the environment, so why is the extra escaping still needed?

image

@parwejmetroag
Copy link

/notepad++.exe' -multiInst -nosession -notabbar"

Above worked for me....have to add correct notepad++ path. However, while saving the file, it keeps saying that file is opened in another program and doesn't allow to save. Any trick to solve this problem? @akunaatrium

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

4 participants