diff options
-rw-r--r-- | doc/bindings | 3 | ||||
-rw-r--r-- | src/bindings.cpp | 8 | ||||
-rw-r--r-- | src/macro_utilities.cpp | 6 | ||||
-rw-r--r-- | src/macro_utilities.h | 12 |
4 files changed, 29 insertions, 0 deletions
diff --git a/doc/bindings b/doc/bindings index e8cd1dda..c7643155 100644 --- a/doc/bindings +++ b/doc/bindings @@ -95,6 +95,9 @@ ## selected_items_adder, server_info, song_info, ## sort_playlist_dialog, tiny_tag_editor. ## +## - run_external_command "command" - runs given command using +## system() function. +## ## 5) In addition to binding to a key, you can also bind actions ## or chains of actions to a command. If it comes to commands, ## syntax is very similar to defining keys. Here goes example diff --git a/src/bindings.cpp b/src/bindings.cpp index 7dfdacd4..838083c1 100644 --- a/src/bindings.cpp +++ b/src/bindings.cpp @@ -147,6 +147,14 @@ Action *parseActionLine(const std::string &line, F error) else error() << "unknown action passed to require_runnable: '" << arg << "'\n"; } + else if (action_name == "run_external_command") + { + std::string command = getEnclosedString(line, '"', '"', 0); + if (!command.empty()) + result = new RunExternalCommand(std::move(command)); + else + error() << "empty command passed to run_external_command\n"; + } } return result; } diff --git a/src/macro_utilities.cpp b/src/macro_utilities.cpp index a2f69c90..05125ad1 100644 --- a/src/macro_utilities.cpp +++ b/src/macro_utilities.cpp @@ -36,3 +36,9 @@ bool RequireScreen::canBeRun() const { return Global::myScreen->type() == m_screen_type; } + +void RunExternalCommand::Run() +{ + GNUC_UNUSED int res; + res = std::system(m_command.c_str()); +} diff --git a/src/macro_utilities.h b/src/macro_utilities.h index d13abda7..14031994 100644 --- a/src/macro_utilities.h +++ b/src/macro_utilities.h @@ -64,4 +64,16 @@ private: ScreenType m_screen_type; }; +struct RunExternalCommand : public Action +{ + RunExternalCommand(std::string command) + : Action(aMacroUtility, ""), m_command(command) { } + +protected: + virtual void Run(); + +private: + std::string m_command; +}; + #endif // NCMPCPP_MACRO_UTILITIES_H |