From 92f94de5038cf745c5f97d79abfbcb1085ceb497 Mon Sep 17 00:00:00 2001 From: Marcos Gabarda Date: Tue, 24 Feb 2026 22:36:46 +0100 Subject: [PATCH] feat: use XDG_RUNTIME_DIR to place the unix socket --- main.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index e953002..6283917 100644 --- a/main.go +++ b/main.go @@ -12,9 +12,6 @@ Flags: Runs cover-viewer in visualizer or notify. In visualizer mode it displays the album cover of the file read from the socket. In notify, reads cmus status line from stdin and sends the file path to the socket. - --socket - Allows to change the location of the UNIX socket used to send and read the cmus - status line. */ package main @@ -53,17 +50,18 @@ func main() { log.SetFlags(log.LstdFlags | log.Lshortfile) mode := flag.String("mode", "", "visualizer or notify") - socketPath := flag.String("socket", "/tmp/music-viewer.sock", "unix socket path") flag.Parse() + socketPath := getSocketPath() + switch *mode { case "visualizer": - if err := runVisualizer(*socketPath); err != nil { + if err := runVisualizer(socketPath); err != nil { fmt.Fprintln(os.Stderr, "visualize error:", err) os.Exit(1) } case "notify": - if err := runNotify(*socketPath); err != nil { + if err := runNotify(socketPath); err != nil { fmt.Fprintln(os.Stderr, "notify error:", err) os.Exit(1) } @@ -73,6 +71,14 @@ func main() { } } +// getSocketPath gets the socket path +func getSocketPath() string { + if xdg := os.Getenv("XDG_RUNTIME_DIR"); xdg != "" { + return xdg + "/music-viewer.sock" + } + return "/tmp/music-viewer.sock" +} + // runNotify writes in the socket the content of the Stdin, meant to be the status // string from cmus. func runNotify(socketPath string) error { -- 2.51.2