Add mpd host selection menu

This commit is contained in:
crater2150 2015-05-24 23:51:07 +02:00
parent 890bdf1866
commit a96cfbb8a1
2 changed files with 46 additions and 24 deletions

View file

@ -35,20 +35,31 @@ bindings.spawnf = spawnf
conf.cmd.run = conf.cmd.run or spawnf("dmenu_run")
local function mpdserver(host)
return function() mpd.set_server(host, "6600") end
end
mpdhosts = {
n = { func = mpdserver("nas.fritz.box"), desc = "NAS" },
b = { func = mpdserver("berryhorst.fritz.box"), desc = "Berry" },
l = { func = mpdserver("127.0.0.1"), desc = "Local" }
}
mpdmap = {
m = { func = mpd.ctrl.toggle, desc = "Toggle" },
n = { func = mpd.ctrl.next, desc = "Next" },
N = { func = mpd.ctrl.prev, desc = "Prev" },
s = { func = spawnf("mpd"), desc = "start MPD" },
S = { func = spawnf("mpd --kill"), desc = "kill MPD" },
g = { func = spawnf(conf.cmd.mpd_client), desc = "Gmpc" }
g = { func = spawnf(conf.cmd.mpd_client), desc = "Gmpc" },
}
mpdpromts = {
a = { func = mpd.prompt.artist, desc = "artist" },
b = { func = mpd.prompt.album, desc = "album" },
t = { func = mpd.prompt.title, desc = "title" },
r = { func = mpd.prompt.toggle_replace_on_search, desc = "toggle replacing" }
r = { func = mpd.prompt.toggle_replace_on_search, desc = "toggle replacing" },
h = { func = mb.grabf(mpdhosts, "Select MPD host"), desc = "Change host" }
}
progmap = {

55
mpd.lua
View file

@ -12,15 +12,43 @@ local defaults = {}
local settings = {}
defaults.replace_on_search = true
defaults.host = "127.0.0.1"
defaults.port = "6600"
for key, value in pairs(defaults) do
settings[key] = value
end
mpc = function(command)
awful.util.spawn("mpc " .. command)
for key, value in pairs(conf.mpd) do
settings[key] = value
end
-- {{{ local helpers
local function mpc(command)
log.spawn("mpc -h " .. settings.host .. " -p " .. settings.port .. " " .. command)
end
local function dmenu(opts)
log.spawn("dmpc -h " .. settings.host .. " -p " .. settings.port .. " " ..
(clear_before and "-r" or "-R") .. " " .. opts)
end
local function notify(stext)
if not (naughty == nil) then
naughty.notify({
text= stext
})
end
end
--}}}
M.set_server = function(host, port)
settings.host = host
settings.port = port
notify("Using mpd server " .. settings.host .. ":" .. settings.port)
end
-- {{{ mpd.ctrl submodule
M.ctrl = {}
@ -49,10 +77,6 @@ end
-- {{{ mpd.prompt submodule
local clear_before = conf.mpd_prompt_clear_before == nil and
true or
conf.mpd_prompt_clear_before
M.prompt = {}
M.prompt.artist = function()
@ -69,32 +93,19 @@ M.prompt.title = function()
end
M.prompt.title = title
function dmenu(opts)
awful.util.spawn("dmpc " .. (clear_before and "-r" or "-R") .. " " .. opts)
end
M.prompt.replace_on_search = function(bool)
clear_before = bool
settings.replace_on_search = bool
end
M.prompt.toggle_replace_on_search = function()
clear_before = not clear_before
settings.replace_on_search = not settings.replace_on_search
notify("MPD prompts now " ..(
clear_before and "replace" or "add to"
settings.replace_on_search and "replace" or "add to"
).. " the playlist")
end
-- }}}
-- {{{ notify wrapper
notify = function(stext)
if not (naughty == nil) then
naughty.notify({
text= stext
})
end
end
--}}}
return M