From cf50c65438359821463ee690d4e006d9770db695 Mon Sep 17 00:00:00 2001 From: brent s Date: Fri, 25 Sep 2020 16:54:33 -0400 Subject: [PATCH] adding func to get PATH var --- paths/paths.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/paths/paths.go b/paths/paths.go index b007e20..7ebbd09 100644 --- a/paths/paths.go +++ b/paths/paths.go @@ -6,10 +6,10 @@ import ( "os" "os/user" "path/filepath" + "strings" ) -// Strings are, apparently, cast as pointers. A lot of the ptr ref/deref below is redundant. -// Regardless, future-prooofing. +var err error func ExpandHome(path *string) error { // Props to this guy. @@ -27,6 +27,17 @@ func ExpandHome(path *string) error { return nil } +func GetPathEnv() ([]string, error) { + paths := []string{} + for _, p := range strings.Split(os.Getenv("PATH"), ":") { + if err = RealPath(&p); err != nil { + return nil, err + } + paths = append(paths, p) + } + return paths, nil +} + func MakeDirIfNotExist(path *string) error { exists, stat, err := RealPathExistsStat(path) if err != nil {