From 92732f9682ac5022710df1d1f03cf23141ec8482 Mon Sep 17 00:00:00 2001 From: "Felipe M." Date: Sun, 23 Mar 2025 21:00:03 +0100 Subject: [PATCH] feat: paths --- paths/user.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 paths/user.go diff --git a/paths/user.go b/paths/user.go new file mode 100644 index 0000000..0810c9d --- /dev/null +++ b/paths/user.go @@ -0,0 +1,20 @@ +package paths + +import ( + "os/user" + "path/filepath" + "strings" +) + +func ExpandUser(providedPath string) string { + var path string = providedPath + usr, _ := user.Current() + dir := usr.HomeDir + + if providedPath == "~" { + path = dir + } else if strings.HasPrefix(providedPath, "~/") { + path = filepath.Join(dir, providedPath[2:]) + } + return path +}