From 72cfd27c30d983a4504684b52bf9f916c8162640 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Sat, 12 Sep 2015 21:49:44 +0200 Subject: [PATCH] configuration: bring back --now-playing (under a different name) --- NEWS | 1 + src/configuration.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/NEWS b/NEWS index 01a92f66..df5bb5c8 100644 --- a/NEWS +++ b/NEWS @@ -30,6 +30,7 @@ ncmpcpp-0.7 (????-??-??) * Tracks in media library are now properly sorted for track numbers greater than 99. * Value of 'visualizer_sync_interval' is now restricted to be greater than 9. * Output of the visualizer now scales automatically as long as 'visualizer_sample_multiplier' is set to 1. +* Command line switch that prints current song to the standard output is available once again. ncmpcpp-0.6.6 (2015-09-07) * A typo in the example configuration file was fixed. diff --git a/src/configuration.cpp b/src/configuration.cpp index 84f0df88..60026c35 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -77,6 +77,7 @@ bool configure(int argc, char **argv) options.add_options() ("host,h", po::value()->default_value("localhost"), "connect to server at host") ("port,p", po::value()->default_value(6600), "connect to server at port") + ("current-song", po::value()->implicit_value("{{{(%l) }{{%a - }%t}}|{%f}}"), "print current song using given format and exit") ("config,c", po::value>(&config_paths)->default_value(default_config_paths, join(default_config_paths, " AND ")), "specify configuration file(s)") ("ignore-config-errors", "ignore unknown and invalid options in configuration files") ("bindings,b", po::value(&bindings_path)->default_value("~/.ncmpcpp/bindings"), "specify bindings file") @@ -186,6 +187,19 @@ bool configure(int argc, char **argv) Mpd.SetPort(vm["port"].as()); Mpd.SetTimeout(Config.mpd_connection_timeout); + // print current song + if (vm.count("current-song")) + { + Mpd.Connect(); + auto s = Mpd.GetCurrentSong(); + if (!s.empty()) + { + auto format = Format::parse(vm["current-song"].as(), Format::Flags::Tag); + std::cout << Format::stringify(format, &s); + return false; + } + } + // custom startup screen if (vm.count("screen")) {