]> git.lizzy.rs Git - micro.git/commitdiff
Fix save with sudo auto-detection and sudo/doas message
authorZachary Yedidia <zyedidia@gmail.com>
Fri, 20 Aug 2021 17:55:59 +0000 (13:55 -0400)
committerZachary Yedidia <zyedidia@gmail.com>
Fri, 20 Aug 2021 17:55:59 +0000 (13:55 -0400)
internal/action/actions.go
internal/buffer/buffer.go

index 17875c691ff1ba2fd9d1e756948ebe8df557ea12..a7561b3dd0a14e151b01e70c3db81ece686f3763 100644 (file)
@@ -1,6 +1,9 @@
 package action
 
 import (
+       "errors"
+       "fmt"
+       "io/fs"
        "regexp"
        "runtime"
        "strings"
@@ -807,7 +810,7 @@ func (h *BufPane) SaveAs() bool {
 func (h *BufPane) saveBufToFile(filename string, action string, callback func()) bool {
        err := h.Buf.SaveAs(filename)
        if err != nil {
-               if strings.HasSuffix(err.Error(), "permission denied") {
+               if errors.Is(err, fs.ErrPermission) {
                        saveWithSudo := func() {
                                err = h.Buf.SaveAsWithSudo(filename)
                                if err != nil {
@@ -824,12 +827,15 @@ func (h *BufPane) saveBufToFile(filename string, action string, callback func())
                        if h.Buf.Settings["autosu"].(bool) {
                                saveWithSudo()
                        } else {
-                               InfoBar.YNPrompt("Permission denied. Do you want to save this file using sudo? (y,n)", func(yes, canceled bool) {
-                                       if yes && !canceled {
-                                               saveWithSudo()
-                                               h.completeAction(action)
-                                       }
-                               })
+                               InfoBar.YNPrompt(
+                                       fmt.Sprintf("Permission denied. Do you want to save this file using %s? (y,n)", config.GlobalSettings["sucmd"].(string)),
+                                       func(yes, canceled bool) {
+                                               if yes && !canceled {
+                                                       saveWithSudo()
+                                                       h.completeAction(action)
+                                               }
+                                       },
+                               )
                                return false
                        }
                } else {
index 188161f2f4aac34c3286fd08df4272319ae9e034..734cf3a2c2596e4fbe5ced9e511057be6153de3d 100644 (file)
@@ -256,7 +256,7 @@ func NewBufferFromFileAtLoc(path string, btype BufType, cursorLoc Loc) (*Buffer,
        }
 
        if readonly && prompt != nil {
-               prompt.Message("Warning: file is readonly - sudo will be attempted when saving")
+               prompt.Message(fmt.Sprintf("Warning: file is readonly - %s will be attempted when saving", config.GlobalSettings["sucmd"].(string)))
                // buf.SetOptionNative("readonly", true)
        }