1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-25 22:12:50 -05:00

feat: doctor command

This commit is contained in:
LuckShiba
2025-12-28 04:42:57 -03:00
parent c281bf3b53
commit ec10c8e301
4 changed files with 703 additions and 1 deletions

View File

@@ -1,8 +1,24 @@
package utils
import "os/exec"
import (
"os/exec"
"strings"
)
func CommandExists(cmd string) bool {
_, err := exec.LookPath(cmd)
return err == nil
}
func IsServiceActive(name string, userService bool) bool {
if !CommandExists("systemctl") {
return false
}
args := []string{"is-active", name}
if userService {
args = []string{"--user", "is-active", name}
}
output, _ := exec.Command("systemctl", args...).Output()
return strings.TrimSpace(string(output)) == "active"
}

View File

@@ -6,6 +6,30 @@ import (
"strings"
)
func xdgDir(envVar string, defaultPath ...string) string {
if dir := os.Getenv(envVar); dir != "" {
return dir
}
home, _ := os.UserHomeDir()
return filepath.Join(append([]string{home}, defaultPath...)...)
}
func XDGConfigHome() string {
return xdgDir("XDG_CONFIG_HOME", ".config")
}
func XDGStateHome() string {
return xdgDir("XDG_STATE_HOME", ".local", "state")
}
func XDGCacheHome() string {
return xdgDir("XDG_CACHE_HOME", ".cache")
}
func XDGDataHome() string {
return xdgDir("XDG_DATA_HOME", ".local", "share")
}
func ExpandPath(path string) (string, error) {
expanded := os.ExpandEnv(path)
expanded = filepath.Clean(expanded)