mirror of
https://github.com/EnumeratedDev/stormfetch.git
synced 2026-09-24 19:56:12 +00:00
Add 'custom' module
This commit is contained in:
+16
-45
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strconv"
|
||||
@@ -19,20 +18,6 @@ type DEWM struct {
|
||||
}
|
||||
|
||||
func GetShell() string {
|
||||
runCommand := func(command string) string {
|
||||
cmd := exec.Command("/bin/sh", "-c", command)
|
||||
workdir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
cmd.Dir = workdir
|
||||
cmd.Env = os.Environ()
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(string(out))
|
||||
}
|
||||
file, err := os.ReadFile("/etc/passwd")
|
||||
if err != nil {
|
||||
return ""
|
||||
@@ -54,13 +39,13 @@ func GetShell() string {
|
||||
case "dash":
|
||||
return "Dash"
|
||||
case "bash":
|
||||
return "Bash " + runCommand("echo $BASH_VERSION")
|
||||
return "Bash " + runCommand("echo $BASH_VERSION", "/bin/sh")
|
||||
case "zsh":
|
||||
return "Zsh " + runCommand("$SHELL --version | awk '{print $2}'")
|
||||
return "Zsh " + runCommand("$SHELL --version | awk '{print $2}'", "/bin/sh")
|
||||
case "fish":
|
||||
return "Fish " + runCommand("$SHELL --version | awk '{print $3}'")
|
||||
return "Fish " + runCommand("$SHELL --version | awk '{print $3}'", "/bin/sh")
|
||||
case "nu":
|
||||
return "Nushell " + runCommand("$SHELL --version")
|
||||
return "Nushell " + runCommand("$SHELL --version", "/bin/sh")
|
||||
default:
|
||||
return "Unknown"
|
||||
}
|
||||
@@ -79,53 +64,39 @@ func GetDEWM() DEWM {
|
||||
processExists := func(process string) bool {
|
||||
return slices.Contains(executables, process)
|
||||
}
|
||||
runCommand := func(command string) string {
|
||||
cmd := exec.Command("/bin/sh", "-c", command)
|
||||
workdir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
cmd.Dir = workdir
|
||||
cmd.Env = os.Environ()
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(string(out))
|
||||
}
|
||||
if processExists("plasmashell") {
|
||||
dewm := DEWM{
|
||||
Name: "KDE Plasma",
|
||||
Type: "DE",
|
||||
Version: runCommand("plasmashell --version | awk '{print $2}'"),
|
||||
Version: runCommand("plasmashell --version | awk '{print $2}'", "/bin/sh"),
|
||||
}
|
||||
return dewm
|
||||
} else if processExists("gnome-session") {
|
||||
dewm := DEWM{
|
||||
Name: "Gnome",
|
||||
Type: "DE",
|
||||
Version: runCommand("gnome-shell --version | awk '{print $3}'"),
|
||||
Version: runCommand("gnome-shell --version | awk '{print $3}'", "/bin/sh"),
|
||||
}
|
||||
return dewm
|
||||
} else if processExists("xfce4-session") {
|
||||
dewm := DEWM{
|
||||
Name: "XFCE",
|
||||
Type: "DE",
|
||||
Version: runCommand("xfce4-session --version | head -n1 | awk '{print $2}'"),
|
||||
Version: runCommand("xfce4-session --version | head -n1 | awk '{print $2}'", "/bin/sh"),
|
||||
}
|
||||
return dewm
|
||||
} else if processExists("cinnamon") {
|
||||
dewm := DEWM{
|
||||
Name: "Cinnamon",
|
||||
Type: "DE",
|
||||
Version: runCommand("cinnamon --version | awk '{print $3}'"),
|
||||
Version: runCommand("cinnamon --version | awk '{print $3}'", "/bin/sh"),
|
||||
}
|
||||
return dewm
|
||||
} else if processExists("mate-panel") {
|
||||
dewm := DEWM{
|
||||
Name: "MATE",
|
||||
Type: "DE",
|
||||
Version: runCommand("mate-about --version | awk '{print $4}'"),
|
||||
Version: runCommand("mate-about --version | awk '{print $4}'", "/bin/sh"),
|
||||
}
|
||||
return dewm
|
||||
} else if processExists("lxsession") {
|
||||
@@ -139,23 +110,23 @@ func GetDEWM() DEWM {
|
||||
dewm := DEWM{
|
||||
Name: "LXQt",
|
||||
Type: "DE",
|
||||
Version: runCommand("lxqt-session --version | head -n1 | awk '{print $2}'"),
|
||||
Version: runCommand("lxqt-session --version | head -n1 | awk '{print $2}'", "/bin/sh"),
|
||||
}
|
||||
return dewm
|
||||
} else if processExists("i3") || processExists("i3-with-shmlog") {
|
||||
dewm := DEWM{
|
||||
Name: "i3",
|
||||
Type: "WM",
|
||||
Version: runCommand("i3 --version | awk '{print $3}'"),
|
||||
Version: runCommand("i3 --version | awk '{print $3}'", "/bin/sh"),
|
||||
}
|
||||
return dewm
|
||||
} else if processExists("sway") {
|
||||
dewm := DEWM{
|
||||
Name: "Sway",
|
||||
Type: "WM",
|
||||
Version: runCommand("sway --version | awk '{print $3}'"),
|
||||
Version: runCommand("sway --version | awk '{print $3}'", "/bin/sh"),
|
||||
}
|
||||
if runCommand("sway --version | awk '{print $1}'") == "swayfx" {
|
||||
if runCommand("sway --version | awk '{print $1}'", "/bin/sh") == "swayfx" {
|
||||
dewm.Name = "SwayFX"
|
||||
} else {
|
||||
dewm.Name = "Sway"
|
||||
@@ -165,21 +136,21 @@ func GetDEWM() DEWM {
|
||||
dewm := DEWM{
|
||||
Name: "Bspwm",
|
||||
Type: "WM",
|
||||
Version: runCommand("bspwm -v"),
|
||||
Version: runCommand("bspwm -v", "/bin/sh"),
|
||||
}
|
||||
return dewm
|
||||
} else if processExists("Hyprland") {
|
||||
dewm := DEWM{
|
||||
Name: "Hyprland",
|
||||
Type: "WM",
|
||||
Version: runCommand("hyprctl version | sed -n 3p | awk '{print $2}' | tr -d 'v,'"),
|
||||
Version: runCommand("hyprctl version | sed -n 3p | awk '{print $2}' | tr -d 'v,'", "/bin/sh"),
|
||||
}
|
||||
return dewm
|
||||
} else if processExists("icewm-session") {
|
||||
dewm := DEWM{
|
||||
Name: "IceWM",
|
||||
Type: "WM",
|
||||
Version: runCommand("icewm --version | awk '{print $2}'"),
|
||||
Version: runCommand("icewm --version | awk '{print $2}'", "/bin/sh"),
|
||||
}
|
||||
return dewm
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user