mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 01:47:51 +08:00
22 lines
378 B
Go
22 lines
378 B
Go
package sysutil
|
|
|
|
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
|
|
}
|