Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for unix socket in MPD widget #316

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions widget/mpd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()

Expand Down