From 05d09b7584b4cd18676c68dd161142044437a7af Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 28 Oct 2025 04:35:07 -0500 Subject: load custom env files --- path.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 path.go (limited to 'path.go') diff --git a/path.go b/path.go new file mode 100644 index 0000000..66a27fe --- /dev/null +++ b/path.go @@ -0,0 +1,49 @@ +package env + +import ( + "os" + "path/filepath" + "strings" + + "go.wit.com/log" +) + +// adds a path to the ENV +func AddPath(newpath string) bool { + path := os.Getenv("PATH") + for _, p := range strings.Split(path, ":") { + log.Info("Looking at path:", p) + if p == newpath { + log.Info("FOUND path:", p) + return false + } + } + path = path + ":" + newpath + log.Info("ADDING PATH:", path) + os.Setenv("PATH", path) + return true +} + +// for "/home/turing/bletchley" returns "~/bletchley" +func RelPath(p string) string { + p = strings.TrimSpace(p) + p = strings.Trim(p, "\"'") + homedir := Get("homeDir") + if strings.HasPrefix(p, homedir) { + p = strings.TrimPrefix(p, homedir) + p = filepath.Join("~", p) + } + return p +} + +// for "~/bletchley" returns "/home/turing/bletchley" +func FullPath(p string) string { + p = strings.TrimSpace(p) + p = strings.Trim(p, "\"'") + homedir := Get("homeDir") + if strings.HasPrefix(p, "~") { + p = strings.TrimPrefix(p, "~") + p = filepath.Join(homedir, p) + } + return p +} -- cgit v1.2.3