INNER CODE UNIT · Go

expandTildePath

zan8in/afrog · cmd/afrog/main.go:523

func expandTildePath(v string) string {
	s := strings.TrimSpace(os.ExpandEnv(v))
	if s == "" {
		return s
	}
	s = filepath.FromSlash(s)
	sep := string(os.PathSeparator)
	if s == "~" || strings.HasPrefix(s, "~"+sep) {
		home, err := os.UserHomeDir()
		if err != nil || home == "" {
			return filepath.Clean(s)
		}
		if s == "~" {
			return home
		}
		return filepath.Join(home, strings.TrimPrefix(s, "~"+sep))
	}
	return filepath.Clean(s)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…