-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
45 lines (40 loc) · 983 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package app
import (
"io/ioutil"
"os"
fp "path/filepath"
"github.com/joypauls/scry/fst"
"gopkg.in/yaml.v2"
)
type Config struct {
ShowHidden bool `yaml:"show-hidden"`
UseEmoji bool `yaml:"use-emoji"`
InitDir *fst.Path // where scry is initialized
Home *fst.Path // actual user home directory
// Add in special character handling here, charsets, emoji swaps, etc.
}
func (c Config) Parse(file string) Config {
// refactor to take a reader?
// should this be checked if it exists? should just error?
f, err := ioutil.ReadFile(fp.Join(c.Home.String(), file))
if err != nil {
// can't find it? ignore?
} else {
err = yaml.Unmarshal(f, &c)
if err != nil {
// problem with the file, ignore?
}
}
return c
}
// Initialize with sensible defaults.
func MakeConfig() Config {
config := Config{}
home, err := os.UserHomeDir()
if err == nil {
config.Home = fst.NewPath(home)
} else {
config.Home = fst.NewPath("")
}
return config
}