Fix multiple spaces when version number is empty

This commit is contained in:
2026-02-16 15:18:12 +02:00
parent 8147d302c8
commit a919ffb71b
3 changed files with 125 additions and 61 deletions
+1 -3
View File
@@ -375,7 +375,7 @@ func initializeModuleMap() {
RegisterModule(localIpModule)
// DEWM module
dewmModule := StormfetchModule{stormfetchModuleConfig: stormfetchModuleConfig{Name: "de_wm", Format: "%3${DEWM_TYPE}: %4${DEWM_NAME} ${DEWM_VERSION} ($DISPLAY_PROTOCOL)"}, Execute: func(sm StormfetchModule) string {
dewmModule := StormfetchModule{stormfetchModuleConfig: stormfetchModuleConfig{Name: "de_wm", Format: "%3${DEWM_TYPE}: %4${DEWM_NAME} ($DISPLAY_PROTOCOL)"}, Execute: func(sm StormfetchModule) string {
// Return empty string if currently in TTY
if os.Getenv("XDG_SESSION_TYPE") == "" || os.Getenv("XDG_SESSION_TYPE") == "tty" {
return ""
@@ -395,8 +395,6 @@ func initializeModuleMap() {
return dewm.Name
case "DEWM_TYPE":
return dewm.Type
case "DEWM_VERSION":
return dewm.Version
case "DISPLAY_PROTOCOL":
return displayProtocol
default:
+22 -8
View File
@@ -146,21 +146,35 @@ func GetInitSystem() string {
// Special cases
// OpenRC check
if _, err := os.Stat("/usr/sbin/openrc"); err == nil {
return "OpenRC " + runCommand("openrc --version | awk '{print $3}'", "/bin/sh")
openrcVersion := runCommand("openrc --version | awk '{print $3}'", "/bin/sh")
if openrcVersion != "" {
return "OpenRC " + openrcVersion
} else {
return "OpenRC"
}
}
// Default PID 1 process name checking
switch process.Executable() {
initName := process.Executable()
initVersion := ""
switch initName {
case "systemd":
return "Systemd " + runCommand("systemctl --version | head -n1 | awk '{print $2}'", "/bin/sh")
initName = "Systemd"
initVersion = runCommand("systemctl --version | head -n1 | awk '{print $2}'", "/bin/sh")
case "runit":
return "Runit"
initName = "Runit"
case "dinit":
return "Dinit " + runCommand("dinit --version | head -n1 | awk '{print substr($3, 1, length($3)-1)}'", "/bin/sh")
initName = "Dinit"
initVersion = runCommand("dinit --version | head -n1 | awk '{print substr($3, 1, length($3)-1)}'", "/bin/sh")
case "enit":
return "Enit " + runCommand("enit --version | awk '{print $3}'", "/bin/sh")
default:
return process.Executable()
initName = "Enit"
initVersion = runCommand("enit --version | awk '{print $3}'", "/bin/sh")
}
if initVersion != "" {
return initName + " " + initVersion
} else {
return initName
}
}
+74 -22
View File
@@ -14,7 +14,6 @@ import (
type DEWM struct {
Name string
Type string
Version string
}
func GetShell() string {
@@ -34,21 +33,30 @@ func GetShell() string {
shell = userInfo[6]
}
}
shellName := filepath.Base(shell)
switch shellName {
case "dash":
return "Dash"
shellName := "Unknown"
shellVersion := ""
switch filepath.Base(shell) {
case "bash":
return "Bash " + runCommand("$SHELL --version | head -n1 | awk '{print $4}'", "/bin/sh")
shellName = "Bash"
shellVersion = runCommand("$SHELL --version | head -n1 | awk '{print $4}'", "/bin/sh")
case "zsh":
return "Zsh " + runCommand("$SHELL --version | awk '{print $2}'", "/bin/sh")
shellName = "Zsh"
shellVersion = runCommand("$SHELL --version | awk '{print $2}'", "/bin/sh")
case "fish":
return "Fish " + runCommand("$SHELL --version | awk '{print $3}'", "/bin/sh")
shellName = "Fish"
shellVersion = runCommand("$SHELL --version | awk '{print $3}'", "/bin/sh")
case "nu":
return "Nushell " + runCommand("$SHELL --version", "/bin/sh")
shellName = "Nushell"
shellVersion = runCommand("$SHELL --version", "/bin/sh")
default:
return "Unknown"
}
if shellVersion != "" {
return shellName + " " + shellVersion
} else {
return shellName
}
}
func GetDEWM() DEWM {
@@ -68,96 +76,140 @@ func GetDEWM() DEWM {
dewm := DEWM{
Name: "KDE Plasma",
Type: "DE",
Version: runCommand("plasmashell --version | awk '{print $2}'", "/bin/sh"),
}
if version := runCommand("plasmashell --version | awk '{print $2}'", "/bin/sh"); version != "" {
dewm.Name += " " + version
}
return dewm
} else if processExists("gnome-session") {
dewm := DEWM{
Name: "Gnome",
Type: "DE",
Version: runCommand("gnome-shell --version | awk '{print $3}'", "/bin/sh"),
}
if version := runCommand("gnome-shell --version | awk '{print $3}'", "/bin/sh"); version != "" {
dewm.Name += " " + version
}
return dewm
} else if processExists("xfce4-session") {
dewm := DEWM{
Name: "XFCE",
Type: "DE",
Version: runCommand("xfce4-session --version | head -n1 | awk '{print $2}'", "/bin/sh"),
}
if version := runCommand("xfce4-session --version | head -n1 | awk '{print $2}'", "/bin/sh"); version != "" {
dewm.Name += " " + version
}
return dewm
} else if processExists("cinnamon") {
dewm := DEWM{
Name: "Cinnamon",
Type: "DE",
Version: runCommand("cinnamon --version | awk '{print $3}'", "/bin/sh"),
}
if version := runCommand("cinnamon --version | awk '{print $3}'", "/bin/sh"); version != "" {
dewm.Name += " " + version
}
return dewm
} else if processExists("mate-panel") {
dewm := DEWM{
Name: "MATE",
Type: "DE",
Version: runCommand("mate-about --version | awk '{print $4}'", "/bin/sh"),
}
if version := runCommand("mate-about --version | awk '{print $4}'", "/bin/sh"); version != "" {
dewm.Name += " " + version
}
return dewm
} else if processExists("lxsession") {
dewm := DEWM{
Name: "LXDE",
Type: "DE",
Version: "",
}
return dewm
} else if processExists("lxqt-session") {
dewm := DEWM{
Name: "LXQt",
Type: "DE",
Version: runCommand("lxqt-session --version | head -n1 | awk '{print $2}'", "/bin/sh"),
}
if version := runCommand("lxqt-session --version | head -n1 | awk '{print $2}'", "/bin/sh"); version != "" {
dewm.Name += " " + version
}
return dewm
} else if processExists("i3") || processExists("i3-with-shmlog") {
dewm := DEWM{
Name: "i3",
Type: "WM",
Version: runCommand("i3 --version | awk '{print $3}'", "/bin/sh"),
}
if version := runCommand("i3 --version | awk '{print $3}'", "/bin/sh"); version != "" {
dewm.Name += " " + version
}
return dewm
} else if processExists("sway") {
dewm := DEWM{
Name: "Sway",
Type: "WM",
Version: runCommand("sway --version | awk '{print $3}'", "/bin/sh"),
}
if runCommand("sway --version | awk '{print $1}'", "/bin/sh") == "swayfx" {
dewm.Name = "SwayFX"
} else {
dewm.Name = "Sway"
}
if version := runCommand("sway --version | awk '{print $3}'", "/bin/sh"); version != "" {
dewm.Name += " " + version
}
return dewm
} else if processExists("bspwm") {
dewm := DEWM{
Name: "Bspwm",
Type: "WM",
Version: runCommand("bspwm -v", "/bin/sh"),
}
if version := runCommand("bspwm -v", "/bin/sh"); version != "" {
dewm.Name += " " + version
}
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,'", "/bin/sh"),
}
if version := runCommand("hyprctl version | sed -n 3p | awk '{print $2}' | tr -d 'v,'", "/bin/sh"); version != "" {
dewm.Name += " " + version
}
return dewm
} else if processExists("icewm-session") {
dewm := DEWM{
Name: "IceWM",
Type: "WM",
Version: runCommand("icewm --version | awk '{print $2}'", "/bin/sh"),
}
if version := runCommand("icewm --version | awk '{print $2}'", "/bin/sh"); version != "" {
dewm.Name += " " + version
}
return dewm
}
return DEWM{
Name: "Unknown",
Type: "Unknown",
Version: "Unknown",
}
}