@@ -2,6 +2,8 @@ package main
22
33import (
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
153155func 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
158208func startDebugServer () error {
0 commit comments