diff --git a/src/modules.go b/src/modules.go index 800375c..9bcf035 100644 --- a/src/modules.go +++ b/src/modules.go @@ -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: diff --git a/src/system.go b/src/system.go index 82a0d46..fe5fc7b 100644 --- a/src/system.go +++ b/src/system.go @@ -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 } } diff --git a/src/user.go b/src/user.go index c2b9266..56341eb 100644 --- a/src/user.go +++ b/src/user.go @@ -12,9 +12,8 @@ import ( ) type DEWM struct { - Name string - Type string - Version string + Name string + Type 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 { @@ -66,98 +74,142 @@ func GetDEWM() DEWM { } if processExists("plasmashell") { dewm := DEWM{ - Name: "KDE Plasma", - Type: "DE", - Version: runCommand("plasmashell --version | awk '{print $2}'", "/bin/sh"), + Name: "KDE Plasma", + Type: "DE", } + + 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"), + Name: "Gnome", + Type: "DE", } + + 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"), + Name: "XFCE", + Type: "DE", } + + 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"), + Name: "Cinnamon", + Type: "DE", } + + 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"), + Name: "MATE", + Type: "DE", } + + 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: "", + Name: "LXDE", + Type: "DE", } + 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"), + Name: "LXQt", + Type: "DE", } + + 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"), + Name: "i3", + Type: "WM", } + + 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"), + Name: "Sway", + Type: "WM", } + 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"), + Name: "Bspwm", + Type: "WM", } + + 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"), + Name: "Hyprland", + Type: "WM", } + + 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"), + Name: "IceWM", + Type: "WM", } + + if version := runCommand("icewm --version | awk '{print $2}'", "/bin/sh"); version != "" { + dewm.Name += " " + version + } + return dewm } return DEWM{ - Name: "Unknown", - Type: "Unknown", - Version: "Unknown", + Name: "Unknown", + Type: "Unknown", } }