Shell: Implemented the 'exec' (or '!') command

This commit is contained in:
Paul Beckingham 2015-10-18 00:18:05 -04:00
parent d3410d8dcd
commit 766e16d22a
4 changed files with 17 additions and 13 deletions

View file

@ -131,7 +131,7 @@
tasksh> list Or any other Taskwarrior command\n\
tasksh> diagnostics Tasksh diagnostics\n\
tasksh> help Tasksh help\n\
tasksh> !ls -al Any shell command. May also use 'exec'\n\
tasksh> exec ls -al Any shell command. May also use '!ls -al'\n\
tasksh> quit End of session. May also use 'exit'\n"
// Help

View file

@ -45,8 +45,8 @@
// tasksh commands.
int cmdHelp ();
int cmdDiagnostics ();
int cmdReview ();
int cmdShell ();
int cmdReview (const std::vector <std::string>&);
int cmdShell (const std::vector <std::string>&);
std::string promptCompose ();
std::string findTaskwarrior ();
@ -113,9 +113,9 @@ static int commandLoop ()
else if (closeEnough ("quit", args[0], 3)) status = -1;
else if (closeEnough ("help", args[0], 3)) status = cmdHelp ();
else if (closeEnough ("diagnostics", args[0], 3)) status = cmdDiagnostics ();
else if (closeEnough ("review", args[0], 3)) status = cmdReview ();
else if (closeEnough ("review", args[0], 3)) status = cmdReview (args);
else if (closeEnough ("exec", args[0], 3) ||
args[0][0] == '!') status = cmdShell ();
args[0][0] == '!') status = cmdShell (args);
else if (command != "")
{
command = "task " + command;

View file

@ -224,7 +224,7 @@ static void reviewLoop (const std::vector <std::string>& uuids)
}
////////////////////////////////////////////////////////////////////////////////
int cmdReview ()
int cmdReview (const std::vector <std::string>& args)
{
// Configure 'reviewed' UDA, but only if necessary.
std::string input;

View file

@ -27,16 +27,20 @@
#include <cmake.h>
#include <vector>
#include <string>
#include <stdlib.h>
#include <text.h>
////////////////////////////////////////////////////////////////////////////////
int cmdShell ()
int cmdShell (const std::vector <std::string>& args)
{
/*
auto status = execute ("task",
{"_get", "rc.uda.reviewed.type"},
input,
output);
*/
std::string combined;
join (combined, " ", args);
// Support '!ls' as well as '! ls'.
if (combined[0] == '!')
combined = combined.substr (1);
system (combined.c_str ());
return 0;
}