2
2
дзеркало https://github.com/Hilbis/Hilbish synced 2025-07-14 14:52:02 +00:00

refactor: move out home abbreviating code to a util function

This commit is contained in:
TorchedSammy 2022-05-17 21:37:42 -04:00
джерело ab8b9c8376
коміт 8b6506b36c
Підписано: sammyette
Ідентифікатор GPG ключа: 904FC49417B44DCD
2 змінених файлів з 10 додано та 3 видалено

@ -240,9 +240,7 @@ func fmtPrompt(prompt string) string {
host, _ := os.Hostname()
cwd, _ := os.Getwd()
if strings.HasPrefix(cwd, curuser.HomeDir) {
cwd = "~" + strings.TrimPrefix(cwd, curuser.HomeDir)
}
cwd = util.AbbrevHome(cwd)
username := curuser.Username
// this will be baked into binary since GOOS is a constant
if runtime.GOOS == "windows" {

@ -166,3 +166,12 @@ func ExpandHome(path string) string {
return path
}
// AbbrevHome changes the user's home directory in the path string to ~ (tilde)
func AbbrevHome(path string) string {
curuser, _ := user.Current()
if strings.HasPrefix(path, curuser.HomeDir) {
return "~" + strings.TrimPrefix(path, curuser.HomeDir)
}
return path
}