Skip to content

Instantly share code, notes, and snippets.

@tomoe-mami
Last active May 11, 2016 10:46
Show Gist options
  • Save tomoe-mami/68c4cb574465f64177af5e23b30b568a to your computer and use it in GitHub Desktop.
Save tomoe-mami/68c4cb574465f64177af5e23b30b568a to your computer and use it in GitHub Desktop.
Example bar item that uses data from mpd_events.lua (https://github.com/tomoe-mami/weechat-scripts/tree/master/mpd_events)
w, script_name = weechat, "mpd_bar_item"
info = {}
function item_cb()
local symbols = { play = "", pause = "▮▮", stop = "" }
info.playback_state = symbols[info["status.state"]]
local fmt = "MPD${color:bar_delim}: "
local flags = {
{ "repeat", "REP" },
{ "random", "RND" },
{ "single", "SNG" },
{ "consume", "CON" }
}
for i, f in ipairs(flags) do
local color = info["status."..f[1]] == "1" and "lightgreen" or "darkgray"
fmt = fmt.."${color:"..color.."}"..f[2].." "
end
fmt = fmt.."${color:bar_delim}${playback_state} ${song.time}${color:bar_fg} "
if info["song.id"] then
if not info["song.artist"] or not info["song.title"] then
fmt = fmt.."${song.basename}"
else
fmt = fmt.."${song.artist} ${color:bar_delim}-${color:bar_fg} ${song.title}"
end
else
fmt = fmt.."Not playing"
end
return w.string_eval_expression(fmt, {}, info, {})
end
function hsignal_cb(_, _, data)
if data.events:match(",song_changed,") or
data.events:match(",state_[^,]+,") or
data.idle_subsystems:match(",options,") then
info = data
w.bar_item_update(script_name)
end
return w.WEECHAT_RC_OK
end
w.register(script_name, "singalaut", "0.1", "WTFPL",
"Example of bar item that uses data from mpd_events.lua script",
"", "")
info = w.info_get_hashtable("mpd_events_data", {})
w.hook_hsignal("mpd_events", "hsignal_cb", "")
w.bar_item_new(script_name, "item_cb", "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment