Use gopsutil for cross-platform process detection

Replace pgrep with gopsutil/v4 for pure Go process detection.
Now fully cross-platform (Linux, FreeBSD, macOS, Windows) with
zero external exec calls. Add Taskfile and test fixture.
This commit is contained in:
2025-12-18 05:41:19 +01:00
parent f1ca1ccaa0
commit 1cca87af90
6 changed files with 172 additions and 5 deletions

20
main.go
View File

@ -5,12 +5,12 @@ import (
"encoding/json"
"fmt"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"github.com/go-git/go-git/v6"
"github.com/shirou/gopsutil/v4/process"
"golang.org/x/sys/unix"
)
@ -118,10 +118,20 @@ func formatContextInfo(contextSize int, usage *struct {
}
func getGiteaStatus() string {
// Check if gitea process is running using pgrep
cmd := exec.Command("pgrep", "-x", "gitea")
if err := cmd.Run(); err == nil {
return green + "●" + reset
// Check if gitea process is running using gopsutil (cross-platform)
procs, err := process.Processes()
if err != nil {
return red + "●" + reset
}
for _, p := range procs {
name, err := p.Name()
if err != nil {
continue
}
if name == "gitea" {
return green + "●" + reset
}
}
return red + "●" + reset
}