-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproc.go
32 lines (28 loc) · 830 Bytes
/
proc.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
package ppow
import (
"strings"
"github.com/dottedmag/termlog"
)
// shortCommand shortens a command to a name we can use in a notification
// header.
func shortCommand(command string) string {
ret := command
parts := strings.Split(command, "\n")
for _, i := range parts {
i = strings.TrimLeft(i, " \t#")
i = strings.TrimRight(i, " \t\\")
if i != "" {
ret = i
break
}
}
return ret
}
// niceHeader tries to produce a nicer process name. We condense whitespace to
// make commands split over multiple lines with indentation more legible, and
// limit the line length to 80 characters.
func niceHeader(preamble string, command string) string {
pre := termlog.DefaultPalette.Timestamp.SprintFunc()(preamble)
command = termlog.DefaultPalette.Header.SprintFunc()(shortCommand(command))
return pre + command
}