i3-blocks-go/blocks/ps/main.go
Simon Vieille c9665b33b3
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
add block ps
2022-08-30 13:33:58 +02:00

38 lines
648 B
Go

package main
import (
"fmt"
r "gitnet.fr/deblan/i3-blocks-go/rendering"
"os"
"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 := os.Args[1]
argName := os.Args[2]
if !ProcessExists(argProcess) {
return
}
value := r.TextWithPadding(argName, r.FB{
Foreground: r.Color("green"),
Background: r.Color("black1"),
})
options := r.NewBlockOptions()
options.FullText = value
block := r.Block("ps", options)
fmt.Println(block)
}