From 194b498f395e30ac5736e39c84e1331ce00a066e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Dub=C3=A9?= Date: Thu, 16 Feb 2017 23:08:00 -0500 Subject: [PATCH] Support for unix socket in MPD widget --- widget/mpd.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/widget/mpd.lua b/widget/mpd.lua index 88b99371..e1c75f3f 100644 --- a/widget/mpd.lua +++ b/widget/mpd.lua @@ -27,6 +27,7 @@ local function factory(args) local args = args or {} local timeout = args.timeout or 2 local password = (args.password and #args.password > 0 and string.format("password %s\\n", args.password)) or "" + local socket = args.socket or os.getenv("HOME") .. "/.config/mpd/socket" local host = args.host or "127.0.0.1" local port = args.port or "6600" local music_dir = args.music_dir or os.getenv("HOME") .. "/Music" @@ -36,10 +37,16 @@ local function factory(args) local notify = args.notify or "on" local followtag = args.followtag or false local settings = args.settings or function() end - - local mpdh = string.format("telnet://%s:%s", host, port) - local echo = string.format("printf \"%sstatus\\ncurrentsong\\nclose\\n\"", password) - local cmd = string.format("%s | curl --connect-timeout 1 -fsm 3 %s", echo, mpdh) + local use_unix_socket = args.use_unix_socket or false + + if not use_unix_socket then + mpdh = string.format("telnet://%s:%s", host, port) + echo = string.format("printf \"%sstatus\\ncurrentsong\\nclose\\n\"", password) + cmd = string.format("%s | curl --connect-timeout 1 -fsm 3 %s", echo, mpdh) + else + echo = string.format("printf \"%sstatus\\ncurrentsong\\nclose\\n\"", password) + cmd = string.format("%s | /usr/bin/ncat -U %s", echo, socket) + end mpd.widget = wibox.widget.textbox()