elvish/util/getwd.go
2016-02-17 01:27:51 +01:00

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
}