adding func to get PATH var

This commit is contained in:
brent s. 2020-09-25 16:54:33 -04:00
parent 8337d9f973
commit cf50c65438
Signed by: bts
GPG Key ID: 8C004C2F93481F6B

View File

@ -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 {