github.com/sercand/please@v13.4.0+incompatible/src/fs/home.go (about)

     1  package fs
     2  
     3  import (
     4  	"os"
     5  	"regexp"
     6  	"strings"
     7  )
     8  
     9  var home = os.Getenv("HOME")
    10  var homeRex = regexp.MustCompile("(?:^|:)(~(?:[/:]|$))")
    11  
    12  // ExpandHomePath expands all prefixes of ~ without a user specifier to $HOME.
    13  func ExpandHomePath(path string) string {
    14  	return homeRex.ReplaceAllStringFunc(path, func(subpath string) string {
    15  		return strings.Replace(subpath, "~", home, -1)
    16  	})
    17  }