mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-09-04 08:07:18 -04:00
Remove pre-existing config directory during init, structure Windows config directory more similarly to UNIX
This commit is contained in:
@@ -4,7 +4,7 @@ package backend
|
|||||||
|
|
||||||
// EntryRoot path to libmutton entry directory
|
// EntryRoot path to libmutton entry directory
|
||||||
var EntryRoot = home + "\\AppData\\Local\\libmutton\\entries"
|
var EntryRoot = home + "\\AppData\\Local\\libmutton\\entries"
|
||||||
var ConfigDir = home + "\\AppData\\Local\\libmutton"
|
var ConfigDir = home + "\\AppData\\Local\\libmutton\\config"
|
||||||
var ConfigPath = ConfigDir + "\\libmutton.ini"
|
var ConfigPath = ConfigDir + "\\libmutton.ini"
|
||||||
|
|
||||||
// PathSeparator defines the character used to separate directories in a path (platform-specific)
|
// PathSeparator defines the character used to separate directories in a path (platform-specific)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package backend
|
package backend
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -65,3 +66,31 @@ func GpgKeyGen() string {
|
|||||||
|
|
||||||
return "libmutton-" + unixTime + " (gpg-libmutton) <github.com/rwinkhart/libmutton>"
|
return "libmutton-" + unixTime + " (gpg-libmutton) <github.com/rwinkhart/libmutton>"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DirInit creates the libmutton directories
|
||||||
|
func DirInit() {
|
||||||
|
// create EntryRoot
|
||||||
|
err := os.MkdirAll(EntryRoot, 0700)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(AnsiError + "Failed to create \"" + EntryRoot + "\":" + err.Error() + AnsiReset)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove existing config directory (if it exists)
|
||||||
|
_, isAccessible := TargetIsFile(ConfigDir, false, 1)
|
||||||
|
if isAccessible {
|
||||||
|
err = os.RemoveAll(ConfigDir)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(AnsiError + "Failed to remove existing config directory: " + err.Error() + AnsiReset)
|
||||||
|
os.Exit(1)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// create config directory w/devices subdirectory
|
||||||
|
err = os.MkdirAll(ConfigDir+PathSeparator+"devices", 0700)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(AnsiError + "Failed to create \"" + ConfigDir + "\":" + err.Error() + AnsiReset)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,29 +3,11 @@
|
|||||||
package backend
|
package backend
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
const FallbackEditor = "vi" // vi is pre-installed on most UNIX systems
|
const FallbackEditor = "vi" // vi is pre-installed on most UNIX systems
|
||||||
|
|
||||||
// DirInit creates the libmutton directories
|
|
||||||
func DirInit() {
|
|
||||||
// create EntryRoot
|
|
||||||
err := os.MkdirAll(EntryRoot, 0700)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(AnsiError + "Failed to create \"" + EntryRoot + "\":" + err.Error() + AnsiReset)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// create config directory w/devices subdirectory
|
|
||||||
err = os.MkdirAll(ConfigDir+"/devices", 0700)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(AnsiError + "Failed to create \"" + ConfigDir + "\":" + err.Error() + AnsiReset)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// textEditorFallback returns the value of the $EDITOR environment variable, or FallbackEditor if it is not set
|
// textEditorFallback returns the value of the $EDITOR environment variable, or FallbackEditor if it is not set
|
||||||
func textEditorFallback() string {
|
func textEditorFallback() string {
|
||||||
// ensure textEditor is set
|
// ensure textEditor is set
|
||||||
|
|||||||
@@ -2,24 +2,8 @@
|
|||||||
|
|
||||||
package backend
|
package backend
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
const FallbackEditor = "nvim" // since there is no pre-installed CLI editor on Windows, default to the most popular one
|
const FallbackEditor = "nvim" // since there is no pre-installed CLI editor on Windows, default to the most popular one
|
||||||
|
|
||||||
// DirInit creates the libmutton directories
|
|
||||||
func DirInit() {
|
|
||||||
// create EntryRoot (includes config directory on Windows)
|
|
||||||
err := os.MkdirAll(EntryRoot, 0700)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(AnsiError + "Failed to create \"" + EntryRoot + "\":" + err.Error() + AnsiReset)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
os.MkdirAll(ConfigDir+"\\devices", 0700)
|
|
||||||
}
|
|
||||||
|
|
||||||
// textEditorFallback returns FallbackEditor
|
// textEditorFallback returns FallbackEditor
|
||||||
func textEditorFallback() string {
|
func textEditorFallback() string {
|
||||||
return FallbackEditor
|
return FallbackEditor
|
||||||
|
|||||||
Reference in New Issue
Block a user