Skip to content

Commit

Permalink
feat(config-regenerate-mac-values) update function to work with "vi" …
Browse files Browse the repository at this point in the history
…command on linux systems
  • Loading branch information
christoph meixner committed Mar 26, 2024
1 parent d9b8cb9 commit d040f61
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion pkg/recipes/sops/sops.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ func (s *sopsWrapper) RegenerateMacValues(filePath string) error {
if exitCode == 51 {
logrus.Infof("Regenerating sops MAC for: %s\n", path)

err := os.Setenv("EDITOR", "vim -es +\"norm Go\" +\":wq\"")
vimCommand, err := getVimCommand()
if err != nil {
return err
}

err = os.Setenv("EDITOR", vimCommand+" -es +\"norm Go\" +\":wq\"")
if err != nil {
return err
}
Expand All @@ -74,3 +79,15 @@ func (s *sopsWrapper) RegenerateMacValues(filePath string) error {

return nil
}

func getVimCommand() (string, error) {
_, err := exec.LookPath("vim")
if err != nil {
_, errVi := exec.LookPath("vi")
if errVi != nil {
return "", fmt.Errorf("neither vim nor vi could be found - if you are a windows user, please install vim")
}
return "vi", nil
}
return "vim", nil
}

0 comments on commit d040f61

Please sign in to comment.