From 5b39640ec1ef5e9e4e98490899d07a365dd02fd8 Mon Sep 17 00:00:00 2001 From: Dominik Date: Fri, 7 Nov 2025 23:14:25 +0100 Subject: [PATCH] Changed install to be in userspace and no root is required --- Makefile | 4 ++-- src/main.go | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index fb3bf53..496c9e7 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ EXECUTABLE = cheatsh PACKAGES = ./src/. BINDIR = bin -SYSCONFDIR = /etc/cheatsh -PREFIX ?= /usr/local +SYSCONFDIR = $(HOME)/.config/cheatsh +PREFIX ?= $(HOME)/.local all: build diff --git a/src/main.go b/src/main.go index 2257da8..9109ff1 100644 --- a/src/main.go +++ b/src/main.go @@ -7,6 +7,7 @@ import ( "encoding/json" "log" "sort" + "path/filepath" ) type CmdGroup struct { @@ -39,10 +40,19 @@ func main() { flag.Parse() - configFile := "/etc/cheatsh/commands.json" + var configFile string + + home, err := os.UserHomeDir() + if err == nil { + userConf := filepath.Join(home, ".config", "cheatsh") + if info, err := os.Stat(userConf); err == nil && info.IsDir() { + configFile = filepath.Join(userConf, "commands.json") + } else { + configFile = "/etc/cheatsh/commands.json" + } + } var commands CmdList - var err error if *configFlag != "" { commands, err = loadCommands(*configFlag)