mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-26 19:39:39 -08:00
chore: backup original config
This commit is contained in:
parent
6b6aec43d5
commit
0621d0d97a
|
@ -5,6 +5,7 @@ import (
|
|||
json2 "encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"oh-my-posh/color"
|
||||
"oh-my-posh/console"
|
||||
"oh-my-posh/environment"
|
||||
|
@ -173,16 +174,8 @@ func (cfg *Config) Export(format string) string {
|
|||
}
|
||||
|
||||
func (cfg *Config) Write() {
|
||||
cfg.write(cfg.origin)
|
||||
}
|
||||
|
||||
func (cfg *Config) Backup() {
|
||||
cfg.write(cfg.origin + ".bak")
|
||||
}
|
||||
|
||||
func (cfg *Config) write(destination string) {
|
||||
content := cfg.Export(cfg.format)
|
||||
f, err := os.OpenFile(destination, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
|
||||
f, err := os.OpenFile(cfg.origin, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
|
||||
cfg.exitWithError(err)
|
||||
_, err = f.WriteString(content)
|
||||
cfg.exitWithError(err)
|
||||
|
@ -191,6 +184,18 @@ func (cfg *Config) write(destination string) {
|
|||
}
|
||||
}
|
||||
|
||||
func (cfg *Config) Backup() {
|
||||
dst := cfg.origin + ".bak"
|
||||
source, err := os.Open(cfg.origin)
|
||||
cfg.exitWithError(err)
|
||||
defer source.Close()
|
||||
destination, err := os.Create(dst)
|
||||
cfg.exitWithError(err)
|
||||
defer destination.Close()
|
||||
_, err = io.Copy(destination, source)
|
||||
cfg.exitWithError(err)
|
||||
}
|
||||
|
||||
func escapeGlyphs(s string) string {
|
||||
var builder strings.Builder
|
||||
for _, r := range s {
|
||||
|
|
Loading…
Reference in a new issue