2
2
zrcadlo https://github.com/Hilbis/Hilbish synchronizováno 2025-07-18 16:52:02 +00:00

refactor: move out home abbreviating code to a util function

Tento commit je obsažen v:
TorchedSammy 2022-05-17 21:37:42 -04:00
rodič ab8b9c8376
revize 8b6506b36c
Podepsáno: sammyette
ID GPG klíče: 904FC49417B44DCD
2 změnil soubory, kde provedl 10 přidání a 3 odebrání

Zobrazit soubor

@ -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" {

Zobrazit soubor

@ -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
}