mirror of https://github.com/Hilbis/Hilbish
refactor: move out home abbreviating code to a util function
parent
ab8b9c8376
commit
8b6506b36c
4
main.go
4
main.go
|
@ -240,9 +240,7 @@ func fmtPrompt(prompt string) string {
|
||||||
host, _ := os.Hostname()
|
host, _ := os.Hostname()
|
||||||
cwd, _ := os.Getwd()
|
cwd, _ := os.Getwd()
|
||||||
|
|
||||||
if strings.HasPrefix(cwd, curuser.HomeDir) {
|
cwd = util.AbbrevHome(cwd)
|
||||||
cwd = "~" + strings.TrimPrefix(cwd, curuser.HomeDir)
|
|
||||||
}
|
|
||||||
username := curuser.Username
|
username := curuser.Username
|
||||||
// this will be baked into binary since GOOS is a constant
|
// this will be baked into binary since GOOS is a constant
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
|
|
|
@ -166,3 +166,12 @@ func ExpandHome(path string) string {
|
||||||
return path
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue