mirror of
https://github.com/EnumeratedDev/stormfetch.git
synced 2026-09-16 07:56:12 +00:00
Fix multiple spaces when version number is empty
This commit is contained in:
+1
-3
@@ -375,7 +375,7 @@ func initializeModuleMap() {
|
|||||||
RegisterModule(localIpModule)
|
RegisterModule(localIpModule)
|
||||||
|
|
||||||
// DEWM module
|
// 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
|
// Return empty string if currently in TTY
|
||||||
if os.Getenv("XDG_SESSION_TYPE") == "" || os.Getenv("XDG_SESSION_TYPE") == "tty" {
|
if os.Getenv("XDG_SESSION_TYPE") == "" || os.Getenv("XDG_SESSION_TYPE") == "tty" {
|
||||||
return ""
|
return ""
|
||||||
@@ -395,8 +395,6 @@ func initializeModuleMap() {
|
|||||||
return dewm.Name
|
return dewm.Name
|
||||||
case "DEWM_TYPE":
|
case "DEWM_TYPE":
|
||||||
return dewm.Type
|
return dewm.Type
|
||||||
case "DEWM_VERSION":
|
|
||||||
return dewm.Version
|
|
||||||
case "DISPLAY_PROTOCOL":
|
case "DISPLAY_PROTOCOL":
|
||||||
return displayProtocol
|
return displayProtocol
|
||||||
default:
|
default:
|
||||||
|
|||||||
+22
-8
@@ -146,21 +146,35 @@ func GetInitSystem() string {
|
|||||||
// Special cases
|
// Special cases
|
||||||
// OpenRC check
|
// OpenRC check
|
||||||
if _, err := os.Stat("/usr/sbin/openrc"); err == nil {
|
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
|
// Default PID 1 process name checking
|
||||||
switch process.Executable() {
|
initName := process.Executable()
|
||||||
|
initVersion := ""
|
||||||
|
switch initName {
|
||||||
case "systemd":
|
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":
|
case "runit":
|
||||||
return "Runit"
|
initName = "Runit"
|
||||||
case "dinit":
|
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":
|
case "enit":
|
||||||
return "Enit " + runCommand("enit --version | awk '{print $3}'", "/bin/sh")
|
initName = "Enit"
|
||||||
default:
|
initVersion = runCommand("enit --version | awk '{print $3}'", "/bin/sh")
|
||||||
return process.Executable()
|
}
|
||||||
|
|
||||||
|
if initVersion != "" {
|
||||||
|
return initName + " " + initVersion
|
||||||
|
} else {
|
||||||
|
return initName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+102
-50
@@ -12,9 +12,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type DEWM struct {
|
type DEWM struct {
|
||||||
Name string
|
Name string
|
||||||
Type string
|
Type string
|
||||||
Version string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetShell() string {
|
func GetShell() string {
|
||||||
@@ -34,21 +33,30 @@ func GetShell() string {
|
|||||||
shell = userInfo[6]
|
shell = userInfo[6]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shellName := filepath.Base(shell)
|
shellName := "Unknown"
|
||||||
switch shellName {
|
shellVersion := ""
|
||||||
case "dash":
|
switch filepath.Base(shell) {
|
||||||
return "Dash"
|
|
||||||
case "bash":
|
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":
|
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":
|
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":
|
case "nu":
|
||||||
return "Nushell " + runCommand("$SHELL --version", "/bin/sh")
|
shellName = "Nushell"
|
||||||
|
shellVersion = runCommand("$SHELL --version", "/bin/sh")
|
||||||
default:
|
default:
|
||||||
return "Unknown"
|
return "Unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if shellVersion != "" {
|
||||||
|
return shellName + " " + shellVersion
|
||||||
|
} else {
|
||||||
|
return shellName
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDEWM() DEWM {
|
func GetDEWM() DEWM {
|
||||||
@@ -66,98 +74,142 @@ func GetDEWM() DEWM {
|
|||||||
}
|
}
|
||||||
if processExists("plasmashell") {
|
if processExists("plasmashell") {
|
||||||
dewm := DEWM{
|
dewm := DEWM{
|
||||||
Name: "KDE Plasma",
|
Name: "KDE Plasma",
|
||||||
Type: "DE",
|
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
|
return dewm
|
||||||
} else if processExists("gnome-session") {
|
} else if processExists("gnome-session") {
|
||||||
dewm := DEWM{
|
dewm := DEWM{
|
||||||
Name: "Gnome",
|
Name: "Gnome",
|
||||||
Type: "DE",
|
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
|
return dewm
|
||||||
} else if processExists("xfce4-session") {
|
} else if processExists("xfce4-session") {
|
||||||
dewm := DEWM{
|
dewm := DEWM{
|
||||||
Name: "XFCE",
|
Name: "XFCE",
|
||||||
Type: "DE",
|
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
|
return dewm
|
||||||
} else if processExists("cinnamon") {
|
} else if processExists("cinnamon") {
|
||||||
dewm := DEWM{
|
dewm := DEWM{
|
||||||
Name: "Cinnamon",
|
Name: "Cinnamon",
|
||||||
Type: "DE",
|
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
|
return dewm
|
||||||
} else if processExists("mate-panel") {
|
} else if processExists("mate-panel") {
|
||||||
dewm := DEWM{
|
dewm := DEWM{
|
||||||
Name: "MATE",
|
Name: "MATE",
|
||||||
Type: "DE",
|
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
|
return dewm
|
||||||
} else if processExists("lxsession") {
|
} else if processExists("lxsession") {
|
||||||
dewm := DEWM{
|
dewm := DEWM{
|
||||||
Name: "LXDE",
|
Name: "LXDE",
|
||||||
Type: "DE",
|
Type: "DE",
|
||||||
Version: "",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return dewm
|
return dewm
|
||||||
} else if processExists("lxqt-session") {
|
} else if processExists("lxqt-session") {
|
||||||
dewm := DEWM{
|
dewm := DEWM{
|
||||||
Name: "LXQt",
|
Name: "LXQt",
|
||||||
Type: "DE",
|
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
|
return dewm
|
||||||
} else if processExists("i3") || processExists("i3-with-shmlog") {
|
} else if processExists("i3") || processExists("i3-with-shmlog") {
|
||||||
dewm := DEWM{
|
dewm := DEWM{
|
||||||
Name: "i3",
|
Name: "i3",
|
||||||
Type: "WM",
|
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
|
return dewm
|
||||||
} else if processExists("sway") {
|
} else if processExists("sway") {
|
||||||
dewm := DEWM{
|
dewm := DEWM{
|
||||||
Name: "Sway",
|
Name: "Sway",
|
||||||
Type: "WM",
|
Type: "WM",
|
||||||
Version: runCommand("sway --version | awk '{print $3}'", "/bin/sh"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if runCommand("sway --version | awk '{print $1}'", "/bin/sh") == "swayfx" {
|
if runCommand("sway --version | awk '{print $1}'", "/bin/sh") == "swayfx" {
|
||||||
dewm.Name = "SwayFX"
|
dewm.Name = "SwayFX"
|
||||||
} else {
|
} else {
|
||||||
dewm.Name = "Sway"
|
dewm.Name = "Sway"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if version := runCommand("sway --version | awk '{print $3}'", "/bin/sh"); version != "" {
|
||||||
|
dewm.Name += " " + version
|
||||||
|
}
|
||||||
|
|
||||||
return dewm
|
return dewm
|
||||||
} else if processExists("bspwm") {
|
} else if processExists("bspwm") {
|
||||||
dewm := DEWM{
|
dewm := DEWM{
|
||||||
Name: "Bspwm",
|
Name: "Bspwm",
|
||||||
Type: "WM",
|
Type: "WM",
|
||||||
Version: runCommand("bspwm -v", "/bin/sh"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if version := runCommand("bspwm -v", "/bin/sh"); version != "" {
|
||||||
|
dewm.Name += " " + version
|
||||||
|
}
|
||||||
|
|
||||||
return dewm
|
return dewm
|
||||||
} else if processExists("Hyprland") {
|
} else if processExists("Hyprland") {
|
||||||
dewm := DEWM{
|
dewm := DEWM{
|
||||||
Name: "Hyprland",
|
Name: "Hyprland",
|
||||||
Type: "WM",
|
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
|
return dewm
|
||||||
} else if processExists("icewm-session") {
|
} else if processExists("icewm-session") {
|
||||||
dewm := DEWM{
|
dewm := DEWM{
|
||||||
Name: "IceWM",
|
Name: "IceWM",
|
||||||
Type: "WM",
|
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
|
||||||
}
|
}
|
||||||
return DEWM{
|
return DEWM{
|
||||||
Name: "Unknown",
|
Name: "Unknown",
|
||||||
Type: "Unknown",
|
Type: "Unknown",
|
||||||
Version: "Unknown",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user