Merge branch 'seitokaichou-autosu'
This commit is contained in:
commit
e18e41eb45
3 changed files with 32 additions and 16 deletions
|
@ -732,23 +732,30 @@ func (h *BufPane) saveBufToFile(filename string, action string, callback func())
|
||||||
err := h.Buf.SaveAs(filename)
|
err := h.Buf.SaveAs(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.HasSuffix(err.Error(), "permission denied") {
|
if strings.HasSuffix(err.Error(), "permission denied") {
|
||||||
InfoBar.YNPrompt("Permission denied. Do you want to save this file using sudo? (y,n)", func(yes, canceled bool) {
|
saveWithSudo := func() {
|
||||||
if yes && !canceled {
|
err = h.Buf.SaveAsWithSudo(filename)
|
||||||
err = h.Buf.SaveAsWithSudo(filename)
|
if err != nil {
|
||||||
if err != nil {
|
InfoBar.Error(err)
|
||||||
InfoBar.Error(err)
|
} else {
|
||||||
} else {
|
h.Buf.Path = filename
|
||||||
h.Buf.Path = filename
|
h.Buf.SetName(filename)
|
||||||
h.Buf.SetName(filename)
|
InfoBar.Message("Saved " + filename)
|
||||||
InfoBar.Message("Saved " + filename)
|
}
|
||||||
|
}
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
h.completeAction(action)
|
if callback != nil {
|
||||||
}
|
callback()
|
||||||
if callback != nil {
|
}
|
||||||
callback()
|
})
|
||||||
}
|
return false
|
||||||
})
|
}
|
||||||
return false
|
|
||||||
} else {
|
} else {
|
||||||
InfoBar.Error(err)
|
InfoBar.Error(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,6 +184,7 @@ func GetGlobalOption(name string) interface{} {
|
||||||
|
|
||||||
var defaultCommonSettings = map[string]interface{}{
|
var defaultCommonSettings = map[string]interface{}{
|
||||||
"autoindent": true,
|
"autoindent": true,
|
||||||
|
"autosu": true,
|
||||||
"backup": true,
|
"backup": true,
|
||||||
"basename": false,
|
"basename": false,
|
||||||
"colorcolumn": float64(0),
|
"colorcolumn": float64(0),
|
||||||
|
|
|
@ -24,6 +24,14 @@ Here are the available options:
|
||||||
|
|
||||||
default value: `0`
|
default value: `0`
|
||||||
|
|
||||||
|
* `autosu`: When a file is saved that the user doesn't have permission to
|
||||||
|
modify, micro will ask if the user would like to use super user
|
||||||
|
privileges to save the file. If this option is enabled, micro will
|
||||||
|
automatically attempt to use super user privileges to save without
|
||||||
|
asking the user.
|
||||||
|
|
||||||
|
default value: `false`
|
||||||
|
|
||||||
* `backup`: micro will automatically keep backups of all open buffers. Backups
|
* `backup`: micro will automatically keep backups of all open buffers. Backups
|
||||||
are stored in `~/.config/micro/backups` and are removed when the buffer is
|
are stored in `~/.config/micro/backups` and are removed when the buffer is
|
||||||
closed cleanly. In the case of a system crash or a micro crash, the contents
|
closed cleanly. In the case of a system crash or a micro crash, the contents
|
||||||
|
|
Loading…
Reference in a new issue