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:
20
main.go
20
main.go
@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user