diff --git a/core/cmd/dms/commands_common.go b/core/cmd/dms/commands_common.go index 14619b53..eccc3043 100644 --- a/core/cmd/dms/commands_common.go +++ b/core/cmd/dms/commands_common.go @@ -2,6 +2,8 @@ package main import ( "fmt" + "os" + "regexp" "strings" "github.com/AvengeMedia/DankMaterialShell/core/internal/log" @@ -152,7 +154,55 @@ var pluginsUninstallCmd = &cobra.Command{ func runVersion(cmd *cobra.Command, args []string) { printASCII() - fmt.Printf("%s\n", Version) + fmt.Printf("%s\n", formatVersion(Version)) +} + +// Git builds: dms (git) v0.6.2-XXXX +// Stable releases: dms v0.6.2 +func formatVersion(version string) string { + // Arch/Debian/Ubuntu/OpenSUSE git format: 0.6.2+git2264.c5c5ce84 + re := regexp.MustCompile(`^([\d.]+)\+git(\d+)\.`) + if matches := re.FindStringSubmatch(version); matches != nil { + return fmt.Sprintf("dms (git) v%s-%s", matches[1], matches[2]) + } + + // Fedora COPR git format: 0.0.git.2267.d430cae9 + re = regexp.MustCompile(`^[\d.]+\.git\.(\d+)\.`) + if matches := re.FindStringSubmatch(version); matches != nil { + baseVersion := getBaseVersion() + return fmt.Sprintf("dms (git) v%s-%s", baseVersion, matches[1]) + } + + // Stable release format: 0.6.2 + re = regexp.MustCompile(`^([\d.]+)$`) + if matches := re.FindStringSubmatch(version); matches != nil { + return fmt.Sprintf("dms v%s", matches[1]) + } + + return fmt.Sprintf("dms %s", version) +} + +func getBaseVersion() string { + paths := []string{ + "/usr/share/quickshell/dms/VERSION", + "/usr/local/share/quickshell/dms/VERSION", + "/etc/xdg/quickshell/dms/VERSION", + } + + for _, path := range paths { + if content, err := os.ReadFile(path); err == nil { + ver := strings.TrimSpace(string(content)) + ver = strings.TrimPrefix(ver, "v") + if re := regexp.MustCompile(`^([\d.]+)`); re.MatchString(ver) { + if matches := re.FindStringSubmatch(ver); matches != nil { + return matches[1] + } + } + } + } + + // Fallback + return "0.6.2" } func startDebugServer() error { diff --git a/quickshell/Modules/Settings/AboutTab.qml b/quickshell/Modules/Settings/AboutTab.qml index df3b7722..11dd1d86 100644 --- a/quickshell/Modules/Settings/AboutTab.qml +++ b/quickshell/Modules/Settings/AboutTab.qml @@ -165,12 +165,24 @@ Item { text: { if (!SystemUpdateService.shellVersion) return "dms"; - // Git versioning to show ex: "dms v0.6.2-2223" let version = SystemUpdateService.shellVersion; - let match = version.match(/^([\d.]+)\+git(\d+)\./); + // Debian/Ubuntu/OpenSUSE git format: 0.6.2+git2264.c5c5ce84 + let match = version.match(/^([\d.]+)\+git(\d+)\./); if (match) { - return `dms v${match[1]}-${match[2]}`; + return `dms (git) v${match[1]}-${match[2]}`; + } + + // Fedora COPR git format: 0.0.git.2267.d430cae9 + match = version.match(/^[\d.]+\.git\.(\d+)\./); + if (match) { + return `dms (git) v0.6.2-${match[1]}`; + } + + // Stable release format: 0.6.2 + match = version.match(/^([\d.]+)$/); + if (match) { + return `dms v${match[1]}`; } return `dms ${version}`;