mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
25 lines
384 B
Go
25 lines
384 B
Go
package util
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
// Getwd returns path of the working directory in a format suitable as the
|
|
// prompt.
|
|
func Getwd() string {
|
|
pwd, err := os.Getwd()
|
|
if err != nil {
|
|
return "?"
|
|
}
|
|
home, err := GetHome("")
|
|
if err == nil {
|
|
if pwd == home {
|
|
return "~"
|
|
} else if strings.HasPrefix(pwd, home+"/") {
|
|
return "~" + pwd[len(home):]
|
|
}
|
|
}
|
|
return pwd
|
|
}
|