diff --git a/README.rst b/README.rst index e8406032b2..84f5219ae4 100644 --- a/README.rst +++ b/README.rst @@ -106,7 +106,8 @@ encryption/decryption transparently and open the cleartext file in an editor please wait while an encryption key is being generated and stored in a secure fashion file written to mynewtestfile.yaml -Editing will happen in whatever ``$EDITOR`` is set to, or, if it's not set, in vim. +Editing will happen in whatever ``$SOPS_EDITOR`` or ``$EDITOR`` is set to, or, if it's +not set, in vim, nano, or vi. Keep in mind that SOPS will wait for the editor to exit, and then try to reencrypt the file. Some GUI editors (atom, sublime) spawn a child process and then exit immediately. They usually have an option to wait for the main editor window to be diff --git a/cmd/sops/edit.go b/cmd/sops/edit.go index 982cfb967e..311c8921a9 100644 --- a/cmd/sops/edit.go +++ b/cmd/sops/edit.go @@ -245,7 +245,12 @@ func hashFile(filePath string) ([]byte, error) { } func runEditor(path string) error { - editor := os.Getenv("EDITOR") + envVar := "SOPS_EDITOR" + editor := os.Getenv(envVar) + if editor == "" { + envVar = "EDITOR" + editor = os.Getenv(envVar) + } var cmd *exec.Cmd if editor == "" { editor, err := lookupAnyEditor("vim", "nano", "vi") @@ -256,7 +261,7 @@ func runEditor(path string) error { } else { parts, err := shlex.Split(editor) if err != nil { - return fmt.Errorf("invalid $EDITOR: %s", editor) + return fmt.Errorf("invalid $%s: %s", envVar, editor) } parts = append(parts, path) cmd = exec.Command(parts[0], parts[1:]...) @@ -275,5 +280,5 @@ func lookupAnyEditor(editorNames ...string) (editorPath string, err error) { return editorPath, nil } } - return "", fmt.Errorf("no editor available: sops attempts to use the editor defined in the EDITOR environment variable, and if that's not set defaults to any of %s, but none of them could be found", strings.Join(editorNames, ", ")) + return "", fmt.Errorf("no editor available: sops attempts to use the editor defined in the SOPS_EDITOR or EDITOR environment variables, and if that's not set defaults to any of %s, but none of them could be found", strings.Join(editorNames, ", ")) } diff --git a/cmd/sops/main.go b/cmd/sops/main.go index 155eaec788..6222aaf66a 100644 --- a/cmd/sops/main.go +++ b/cmd/sops/main.go @@ -137,7 +137,8 @@ func main() { To use a different GPG binary than the one in your PATH, set SOPS_GPG_EXEC. - To select a different editor than the default (vim), set EDITOR. + To select a different editor than the default (vim), set SOPS_EDITOR or + EDITOR. Note that flags must always be provided before the filename to operate on. Otherwise, they will be ignored.