expandTilde replaces a leading ~ with the user's home directory.
(path string)
| 160 | |
| 161 | // expandTilde replaces a leading ~ with the user's home directory. |
| 162 | func expandTilde(path string) (string, error) { |
| 163 | if path == "~" { |
| 164 | return os.UserHomeDir() |
| 165 | } |
| 166 | if strings.HasPrefix(path, "~/") { |
| 167 | home, err := os.UserHomeDir() |
| 168 | if err != nil { |
| 169 | return "", fmt.Errorf("expand ~: %w", err) |
| 170 | } |
| 171 | return filepath.Join(home, path[2:]), nil |
| 172 | } |
| 173 | return path, nil |
| 174 | } |
no outgoing calls