mirror of
https://gitlab.com/pnx/gosh
synced 2026-06-15 23:03:09 +02:00
20 lines
447 B
Go
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
|
|
}
|