mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-15 20:17:50 +08:00
22 lines
375 B
Go
22 lines
375 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 := os.Getenv("HOME")
|
|
home = strings.TrimRight(home, "/")
|
|
if len(pwd) >= len(home) && pwd[:len(home)] == home {
|
|
return "~" + pwd[len(home):]
|
|
}
|
|
return pwd
|
|
}
|