feat: paths
This commit is contained in:
parent
5cdbbd2296
commit
92732f9682
1 changed files with 20 additions and 0 deletions
20
paths/user.go
Normal file
20
paths/user.go
Normal file
|
@ -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
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue