1
0
Fork 0
mirror of https://gitlab.com/pnx/gosh synced 2026-06-16 07:04:57 +02:00
gosh/internal/paths/expand.go
2025-10-27 02:03:02 +01:00

20 lines
447 B
Go

package paths
import (
"path/filepath"
)
// Expand resolves shell-like shortcuts in a path string:
// - empty string resolves to the user's home directory
// - leading '~' expands to the user's home directory
func Expand(dir string) string {
// Empty string resolves to the users home dir.
if len(dir) < 1 {
return HomeDir()
}
// Expand ~ to users home dir.
if dir[0] == '~' {
return filepath.Join(HomeDir(), dir[1:])
}
return dir
}