From 6f96757fc4e9ed3aa7d77681b8401521a1a681a9 Mon Sep 17 00:00:00 2001 From: akir Date: Wed, 6 Oct 2004 11:40:28 +0000 Subject: added :Export / :Setenv command --- src/FbCommandFactory.cc | 19 +++++++++++++++++-- src/FbCommands.cc | 11 ++++++++++- src/FbCommands.hh | 12 +++++++++++- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/FbCommandFactory.cc b/src/FbCommandFactory.cc index 7dc7fc8..4e6adf9 100644 --- a/src/FbCommandFactory.cc +++ b/src/FbCommandFactory.cc @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: FbCommandFactory.cc,v 1.35 2004/09/16 14:58:28 rathnor Exp $ +// $Id: FbCommandFactory.cc,v 1.36 2004/10/06 11:40:28 akir Exp $ #include "FbCommandFactory.hh" @@ -66,6 +66,7 @@ FbCommandFactory::FbCommandFactory() { "commanddialog", "deiconify", "detachclient", + "export", "exec", "execcommand", "execute", @@ -116,6 +117,7 @@ FbCommandFactory::FbCommandFactory() { "rightworkspace", "rootmenu", "saverc", + "setenv", "sendtoworkspace", "sendtonextworkspace", "sendtoprevworkspace", @@ -176,8 +178,21 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command, return new SaveResources(); else if (command == "execcommand" || command == "execute" || command == "exec") return new ExecuteCmd(arguments); // execute command on key screen - else if (command == "exit") + else if (command == "exit") return new ExitFluxboxCmd(); + else if (command == "setenv" || command == "export") { + + std::string name = arguments; + FbTk::StringUtil::removeFirstWhitespace(name); + FbTk::StringUtil::removeTrailingWhitespace(name); + size_t pos = name.find_first_of(command == "setenv" ? " \t" : "="); + if (pos == std::string::npos || pos == name.size()) + return 0; + + std::string value = name.substr(pos + 1); + name = name.substr(0, pos); + return new ExportCmd(name, value); + } else if (command == "quit") return new FbTk::SimpleCommand(*Fluxbox::instance(), &Fluxbox::shutdown); else if (command == "commanddialog") // run specified fluxbox command diff --git a/src/FbCommands.cc b/src/FbCommands.cc index 6a9c548..b57534c 100644 --- a/src/FbCommands.cc +++ b/src/FbCommands.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: FbCommands.cc,v 1.27 2004/09/11 20:28:35 fluxgen Exp $ +// $Id: FbCommands.cc,v 1.28 2004/10/06 11:40:28 akir Exp $ #include "FbCommands.hh" #include "fluxbox.hh" @@ -123,6 +123,15 @@ void ExecuteCmd::execute() { } +ExportCmd::ExportCmd(const std::string& name, const std::string& value) : + m_name(name), m_value(value) { +} + +void ExportCmd::execute() { + setenv(m_name.c_str(), m_value.c_str(), 1); +} + + void ExitFluxboxCmd::execute() { Fluxbox::instance()->shutdown(); } diff --git a/src/FbCommands.hh b/src/FbCommands.hh index bc67610..46b3465 100644 --- a/src/FbCommands.hh +++ b/src/FbCommands.hh @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: FbCommands.hh,v 1.19 2004/04/22 21:12:33 fluxgen Exp $ +// $Id: FbCommands.hh,v 1.20 2004/10/06 11:40:28 akir Exp $ // \file contains basic commands to restart, reconfigure, execute command and exit fluxbox @@ -42,6 +42,16 @@ private: const int m_screen_num; }; +/// sets environment +class ExportCmd : public FbTk::Command { +public: + ExportCmd(const std::string& name, const std::string& value); + void execute(); +private: + std::string m_name; + std::string m_value; +}; + /// exit fluxbox class ExitFluxboxCmd: public FbTk::Command { public: -- cgit v0.11.2