Skip to content

Commit e151359

Browse files
committed
DMS Version Formatting
1 parent d430cae commit e151359

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

core/cmd/dms/commands_common.go

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package main
22

33
import (
44
"fmt"
5+
"os"
6+
"regexp"
57
"strings"
68

79
"github.com/AvengeMedia/DankMaterialShell/core/internal/log"
@@ -152,7 +154,55 @@ var pluginsUninstallCmd = &cobra.Command{
152154

153155
func runVersion(cmd *cobra.Command, args []string) {
154156
printASCII()
155-
fmt.Printf("%s\n", Version)
157+
fmt.Printf("%s\n", formatVersion(Version))
158+
}
159+
160+
// Git builds: dms (git) v0.6.2-XXXX
161+
// Stable releases: dms v0.6.2
162+
func formatVersion(version string) string {
163+
// Arch/Debian/Ubuntu/OpenSUSE git format: 0.6.2+git2264.c5c5ce84
164+
re := regexp.MustCompile(`^([\d.]+)\+git(\d+)\.`)
165+
if matches := re.FindStringSubmatch(version); matches != nil {
166+
return fmt.Sprintf("dms (git) v%s-%s", matches[1], matches[2])
167+
}
168+
169+
// Fedora COPR git format: 0.0.git.2267.d430cae9
170+
re = regexp.MustCompile(`^[\d.]+\.git\.(\d+)\.`)
171+
if matches := re.FindStringSubmatch(version); matches != nil {
172+
baseVersion := getBaseVersion()
173+
return fmt.Sprintf("dms (git) v%s-%s", baseVersion, matches[1])
174+
}
175+
176+
// Stable release format: 0.6.2
177+
re = regexp.MustCompile(`^([\d.]+)$`)
178+
if matches := re.FindStringSubmatch(version); matches != nil {
179+
return fmt.Sprintf("dms v%s", matches[1])
180+
}
181+
182+
return fmt.Sprintf("dms %s", version)
183+
}
184+
185+
func getBaseVersion() string {
186+
paths := []string{
187+
"/usr/share/quickshell/dms/VERSION",
188+
"/usr/local/share/quickshell/dms/VERSION",
189+
"/etc/xdg/quickshell/dms/VERSION",
190+
}
191+
192+
for _, path := range paths {
193+
if content, err := os.ReadFile(path); err == nil {
194+
ver := strings.TrimSpace(string(content))
195+
ver = strings.TrimPrefix(ver, "v")
196+
if re := regexp.MustCompile(`^([\d.]+)`); re.MatchString(ver) {
197+
if matches := re.FindStringSubmatch(ver); matches != nil {
198+
return matches[1]
199+
}
200+
}
201+
}
202+
}
203+
204+
// Fallback
205+
return "0.6.2"
156206
}
157207

158208
func startDebugServer() error {

quickshell/Modules/Settings/AboutTab.qml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,24 @@ Item {
165165
text: {
166166
if (!SystemUpdateService.shellVersion) return "dms";
167167

168-
// Git versioning to show ex: "dms v0.6.2-2223"
169168
let version = SystemUpdateService.shellVersion;
169+
170+
// Debian/Ubuntu/OpenSUSE git format: 0.6.2+git2264.c5c5ce84
170171
let match = version.match(/^([\d.]+)\+git(\d+)\./);
172+
if (match) {
173+
return `dms (git) v${match[1]}-${match[2]}`;
174+
}
175+
176+
// Fedora COPR git format: 0.0.git.2267.d430cae9
177+
match = version.match(/^[\d.]+\.git\.(\d+)\./);
178+
if (match) {
179+
return `dms (git) v0.6.2-${match[1]}`;
180+
}
171181

182+
// Stable release format: 0.6.2
183+
match = version.match(/^([\d.]+)$/);
172184
if (match) {
173-
return `dms v${match[1]}-${match[2]}`;
185+
return `dms v${match[1]}`;
174186
}
175187

176188
return `dms ${version}`;

0 commit comments

Comments
 (0)