added :Export / :Setenv command
akir akir
3 files changed,
38 insertions(+),
4 deletions(-)
M
src/FbCommandFactory.cc
→
src/FbCommandFactory.cc
@@ -20,7 +20,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// 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 @@ "close",
"commanddialog", "deiconify", "detachclient", + "export", "exec", "execcommand", "execute",@@ -116,6 +117,7 @@ "restart",
"rightworkspace", "rootmenu", "saverc", + "setenv", "sendtoworkspace", "sendtonextworkspace", "sendtoprevworkspace",@@ -176,8 +178,21 @@ else if (command == "saverc")
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>(*Fluxbox::instance(), &Fluxbox::shutdown); else if (command == "commanddialog") // run specified fluxbox command
M
src/FbCommands.cc
→
src/FbCommands.cc
@@ -19,7 +19,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// 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"@@ -122,6 +122,15 @@ spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", m_cmd.c_str(), 0);
#endif // !__EMX__ } + +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();
M
src/FbCommands.hh
→
src/FbCommands.hh
@@ -19,7 +19,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// 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@@ -40,6 +40,16 @@ void execute();
private: std::string m_cmd; 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