diff --git a/Makefile b/Makefile index eff5382..59b2538 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ GO ?= $(shell which go) build: mkdir -p build - cd src/; $(GO) build -ldflags "-w" -o ../build/typer + cd src/; $(GO) build -ldflags "-w -X 'main.sysconfdir=$(SYSCONFDIR)'" -o ../build/typer install: build/typer # Create directories @@ -24,4 +24,4 @@ uninstall: clean: rm -r build/ -.PHONY: build \ No newline at end of file +.PHONY: build diff --git a/README.md b/README.md index 40be0cf..c112f37 100644 --- a/README.md +++ b/README.md @@ -20,5 +20,5 @@ make ``` - Run the following command **with superuser privileges** to install Typer to your system ```shell -make install SYSCONFDIR=/etc -``` \ No newline at end of file +make install +``` diff --git a/src/config.go b/src/config.go index 6923c92..66fe1c1 100644 --- a/src/config.go +++ b/src/config.go @@ -44,8 +44,8 @@ func readConfig() { if err != nil { log.Fatalf("Could not unmarshal config.yml: %s", err) } - } else if _, err := os.Stat("/etc/typer/config.yml"); err == nil { - reader, err := os.Open("/etc/typer/config.yml") + } else if _, err := os.Stat(path.Join(sysconfdir, "typer/config.yml")); err == nil { + reader, err := os.Open(path.Join(sysconfdir, "typer/config.yml")) if err != nil { log.Fatalf("Could not read config.yml: %s", err) } diff --git a/src/keybindings.go b/src/keybindings.go index 0588cc1..132c96c 100644 --- a/src/keybindings.go +++ b/src/keybindings.go @@ -40,8 +40,8 @@ func readKeybindings() { if err != nil { log.Fatalf("Could not unmarshal keybindings.yml: %s", err) } - } else if _, err := os.Stat("/etc/typer/keybindings.yml"); err == nil { - reader, err := os.Open("/etc/typer/keybindings.yml") + } else if _, err := os.Stat(path.Join(sysconfdir, "typer/keybindings.yml")); err == nil { + reader, err := os.Open(path.Join(sysconfdir, "typer/keybindings.yml")) if err != nil { log.Fatalf("Could not read keybindings.yml: %s", err) } diff --git a/src/main.go b/src/main.go index 50657bd..51e3a88 100644 --- a/src/main.go +++ b/src/main.go @@ -5,6 +5,8 @@ import ( "os" ) +var sysconfdir = "/etc/" + func main() { // Read config readConfig() diff --git a/src/style.go b/src/style.go index d1780dc..e67e4a8 100644 --- a/src/style.go +++ b/src/style.go @@ -94,14 +94,14 @@ func readStyles() { } } } - if stat, err := os.Stat("/etc/typer/styles/"); err == nil && stat.IsDir() { - entries, err := os.ReadDir("/etc/typer/styles/") + if stat, err := os.Stat(path.Join(sysconfdir, "typer/styles/")); err == nil && stat.IsDir() { + entries, err := os.ReadDir(path.Join(sysconfdir, "typer/styles/")) if err != nil { log.Fatalf("Could not read user style directory: %s", err) } for _, entry := range entries { - entryPath := path.Join("/etc/typer/styles/", entry.Name()) + entryPath := path.Join(path.Join(sysconfdir, "typer/styles/"), entry.Name()) style, err := readStyleYamlFile(entryPath) if err != nil { log.Fatalf("Could not read style file (%s): %s", entryPath, err)