From aae0f4630e5d834f0b5f78c5b6a27212e69e5e3f Mon Sep 17 00:00:00 2001 From: prez Date: Wed, 11 Sep 2019 15:35:41 +0200 Subject: [PATCH] Added option to automatically save files with sucmd --- cmd/micro/actions.go | 7 ++++++- cmd/micro/settings.go | 1 + runtime/help/options.md | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/micro/actions.go b/cmd/micro/actions.go index 83eec144..761ae51b 100644 --- a/cmd/micro/actions.go +++ b/cmd/micro/actions.go @@ -994,7 +994,12 @@ func (v *View) saveToFile(filename string) { err := v.Buf.SaveAs(filename) if err != nil { if strings.HasSuffix(err.Error(), "permission denied") { - choice, _ := messenger.YesNoPrompt("Permission denied. Do you want to save this file using sudo? (y,n)") + var choice bool + if globalSettings["autosu"].(bool) { + choice = true + } else { + choice, _ = messenger.YesNoPrompt("Permission denied. Do you want to save this file using sudo? (y,n)") + } if choice { err = v.Buf.SaveAsWithSudo(filename) if err != nil { diff --git a/cmd/micro/settings.go b/cmd/micro/settings.go index c8e50e12..dcae0ef5 100644 --- a/cmd/micro/settings.go +++ b/cmd/micro/settings.go @@ -236,6 +236,7 @@ func DefaultGlobalSettings() map[string]interface{} { "splitright": true, "statusline": true, "sucmd": "sudo", + "autosu": false, "syntax": true, "tabmovement": false, "tabsize": float64(4), diff --git a/runtime/help/options.md b/runtime/help/options.md index 0a85d4ae..679a1ab6 100644 --- a/runtime/help/options.md +++ b/runtime/help/options.md @@ -210,6 +210,10 @@ Here are the options that you can set: default value: `sudo` +* `autosu`: defines whether super user saving should be used automatically. + + default value: `false` + * `tabmovement`: navigate spaces at the beginning of lines as if they are tabs (e.g. move over 4 spaces at once). This option only does anything if `tabstospaces` is on.