diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2017-08-19 18:29:41 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2017-08-19 18:29:41 +0200 |
| commit | 5c3787bd979611712f7dc7ce534355c64bdab430 (patch) | |
| tree | 02089350c699f41baaa9c97b380c4163391827af /pkg/prompt/main.go | |
| parent | dbb1840daf3485edb0e66722fc7e3a608028b59a (diff) | |
| download | gofu-5c3787bd979611712f7dc7ce534355c64bdab430.tar.gz | |
prettyprompt: implement basic cwd display
Diffstat (limited to 'pkg/prompt/main.go')
| -rw-r--r-- | pkg/prompt/main.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/pkg/prompt/main.go b/pkg/prompt/main.go index 8ff56c9..dac8495 100644 --- a/pkg/prompt/main.go +++ b/pkg/prompt/main.go @@ -34,6 +34,9 @@ func Exec() int { fields := []string{ getLoginField(), } + cwd := CurrentDirectory() + fields = appendUnlessEmpty(fields, getDirectoryField(cwd)) + line := strings.Join(fields, " ") lineWidth := getPrintableLength(line) @@ -51,7 +54,7 @@ func Exec() int { for idx := range dashes { dashes[idx] = '-' } - line += string(dashes) + line += withColor("1", string(dashes)) } os.Stdout.Write([]byte(line + "\n")) @@ -66,6 +69,13 @@ func getenvOrDefault(key, defaultValue string) (value string) { return } +func appendUnlessEmpty(list []string, val string) []string { + if val == "" { + return list + } + return append(list, val) +} + func handleError(err error) { if err != nil { os.Stderr.Write([]byte("\x1B[1;31mPrompt error: " + err.Error() + "\x1B[0m\n")) |
