]> git.lizzy.rs Git - micro.git/commitdiff
Only use settings.json if ~/.micro exists
authorZachary Yedidia <zyedidia@gmail.com>
Mon, 18 Apr 2016 01:49:36 +0000 (21:49 -0400)
committerZachary Yedidia <zyedidia@gmail.com>
Mon, 18 Apr 2016 01:49:36 +0000 (21:49 -0400)
Fixes #3

src/settings.go

index 106fe8c40db539e492851802c4b8f2cba92791ba..0e026f5d1d5768c9e2ad7a8fe373b4de5d7a03dc 100644 (file)
@@ -51,8 +51,15 @@ func InitSettings() {
 
 // WriteSettings writes the settings to the specified filename as JSON
 func WriteSettings(filename string) error {
-       txt, _ := json.MarshalIndent(settings, "", "    ")
-       err := ioutil.WriteFile(filename, txt, 0644)
+       var err error
+       home, err := homedir.Dir()
+       if err != nil {
+               return err
+       }
+       if _, e := os.Stat(home + "/.micro"); e == nil {
+               txt, _ := json.MarshalIndent(settings, "", "    ")
+               err = ioutil.WriteFile(filename, txt, 0644)
+       }
        return err
 }