diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2017-08-19 20:42:41 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2017-08-19 20:42:41 +0200 |
| commit | b017ff3fbf272808839e344210741206d94d50da (patch) | |
| tree | 1e51fdbe05e221d344f3112ee3e4dd5277aca12e /pkg/prompt | |
| parent | 39cbf9b61a0a22f0f6310a1dbcbe3268c26d786a (diff) | |
| download | gofu-b017ff3fbf272808839e344210741206d94d50da.tar.gz | |
prettyprompt: show exit code of previous command
Diffstat (limited to 'pkg/prompt')
| -rw-r--r-- | pkg/prompt/main.go | 6 | ||||
| -rw-r--r-- | pkg/prompt/misc.go | 13 |
2 files changed, 17 insertions, 2 deletions
diff --git a/pkg/prompt/main.go b/pkg/prompt/main.go index e5096e8..419b704 100644 --- a/pkg/prompt/main.go +++ b/pkg/prompt/main.go @@ -30,7 +30,7 @@ import ( //Exec executes the prettyprompt applet and returns an exit code (0 for //success, >0 for error). -func Exec() int { +func Exec(args []string) int { fields := []string{ getLoginField(), } @@ -39,6 +39,10 @@ func Exec() int { fields = appendUnlessEmpty(fields, getDeletedMessageField(cwd)) fields = appendUnlessEmpty(fields, getRepoStatusField(cwd.RepoRootPath)) fields = appendUnlessEmpty(fields, getTerminalField()) + //this field should always be last + if len(args) > 0 { + fields = appendUnlessEmpty(fields, getExitCodeField(args[0])) + } line := strings.Join(fields, " ") lineWidth := getPrintableLength(line) diff --git a/pkg/prompt/misc.go b/pkg/prompt/misc.go index eaa1848..124015a 100644 --- a/pkg/prompt/misc.go +++ b/pkg/prompt/misc.go @@ -18,7 +18,10 @@ package prompt -import "os" +import ( + "os" + "strconv" +) func getTerminalField() string { termName := os.Getenv("TERM") @@ -30,3 +33,11 @@ func getTerminalField() string { } return withType("term", termName) } + +func getExitCodeField(arg string) string { + exitCode, err := strconv.Atoi(arg) + if err == nil && exitCode > 0 { + return withColor("1;31", "exit:"+arg) + } + return "" +} |
