i3-blocks-go/blocks/ps/main.go

39 lines
734 B
Go
Raw Normal View History

2022-08-30 13:33:58 +02:00
package main
import (
2022-08-30 15:42:28 +02:00
"flag"
2022-08-30 13:33:58 +02:00
"fmt"
r "gitnet.fr/deblan/i3-blocks-go/rendering"
"os/exec"
"strings"
)
func ProcessExists(process string) bool {
output, _ := exec.Command("pgrep", "-f", process).Output()
lines := strings.TrimSpace(string(output))
count := strings.Count(lines, "\n")
return count > 1
}
func main() {
2022-08-30 15:42:28 +02:00
argProcess := flag.String("process", "", "the process")
argMessage := flag.String("message", "", "the message")
flag.Parse()
2022-08-30 13:33:58 +02:00
2022-08-30 15:42:28 +02:00
if !ProcessExists(*argProcess) {
2022-08-30 13:33:58 +02:00
return
}
2022-08-30 15:42:28 +02:00
value := r.TextWithPadding(*argMessage, r.FB{
2022-08-30 13:33:58 +02:00
Foreground: r.Color("green"),
Background: r.Color("black1"),
})
options := r.NewBlockOptions()
options.FullText = value
block := r.Block("ps", options)
fmt.Println(block)
}