forked from justjanne/powerline-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
segment-exitcode.go
84 lines (81 loc) · 1.48 KB
/
segment-exitcode.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"fmt"
pwl "github.com/justjanne/powerline-go/powerline"
"strconv"
)
func getMeaningFromExitCode(exitCode int) string {
switch exitCode {
case 1:
return "ERROR"
case 2:
return "USAGE"
case 126:
return "NOPERM"
case 127:
return "NOTFOUND"
case 128 + 1:
return "SIGHUP"
case 128 + 2:
return "SIGINT"
case 128 + 3:
return "SIGQUIT"
case 128 + 4:
return "SIGILL"
case 128 + 5:
return "SIGTRAP"
case 128 + 6:
return "SIGIOT"
case 128 + 7:
return "SIGBUS"
case 128 + 8:
return "SIGFPE"
case 128 + 9:
return "SIGKILL"
case 128 + 10:
return "SIGUSR1"
case 128 + 11:
return "SIGSEGV"
case 128 + 12:
return "SIGUSR2"
case 128 + 13:
return "SIGPIPE"
case 128 + 14:
return "SIGALRM"
case 128 + 15:
return "SIGTERM"
case 128 + 16:
return "SIGSTKFLT"
case 128 + 17:
return "SIGCHLD"
case 128 + 18:
return "SIGCONT"
case 128 + 19:
return "SIGSTOP"
case 128 + 20:
return "SIGTSTP"
case 128 + 21:
return "SIGTTIN"
case 128 + 22:
return "SIGTTOU"
default:
return fmt.Sprintf("%d", exitCode)
}
}
func segmentExitCode(p *powerline) []pwl.Segment {
var meaning string
if *p.args.PrevError != 0 {
if *p.args.NumericExitCodes {
meaning = strconv.Itoa(*p.args.PrevError)
} else {
meaning = getMeaningFromExitCode(*p.args.PrevError)
}
return []pwl.Segment{{
Name: "exit",
Content: meaning,
Foreground: p.theme.CmdFailedFg,
Background: p.theme.CmdFailedBg,
}}
}
return []pwl.Segment{}
}