i3-blocks-go/blocks/ps/main.go
Simon Vieille 79fe14e059
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
use flag instead os os.Args
2022-08-30 15:42:28 +02:00

39 lines
734 B
Go

package main
import (
"flag"
"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() {
argProcess := flag.String("process", "", "the process")
argMessage := flag.String("message", "", "the message")
flag.Parse()
if !ProcessExists(*argProcess) {
return
}
value := r.TextWithPadding(*argMessage, r.FB{
Foreground: r.Color("green"),
Background: r.Color("black1"),
})
options := r.NewBlockOptions()
options.FullText = value
block := r.Block("ps", options)
fmt.Println(block)
}