mirror of
https://github.com/GothenburgBitFactory/taskshell.git
synced 2025-07-07 20:06:42 +02:00
Merge pull request #45 from ThomasAdam/gh/15
Allow tasksh to process cmdline args
This commit is contained in:
commit
6c80122d18
3 changed files with 64 additions and 26 deletions
2
NEWS
2
NEWS
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
New Features in tasksh 1.3.0
|
New Features in tasksh 1.3.0
|
||||||
|
|
||||||
-
|
- tasksh passes command-line arguments through to taskwarrior.
|
||||||
|
|
||||||
New commands in tasksh 1.3.0
|
New commands in tasksh 1.3.0
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
tasksh \- Interactive taskwarrior shell
|
tasksh \- Interactive taskwarrior shell
|
||||||
|
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B tasksh
|
.B tasksh [task commands]...
|
||||||
.br
|
.br
|
||||||
.B tasksh --version
|
.B tasksh --version
|
||||||
|
|
||||||
|
@ -18,6 +18,9 @@ When built with libreadline, tasksh provides command editing and history.
|
||||||
Tasksh has an integrated 'review' command that leads you through an interactive
|
Tasksh has an integrated 'review' command that leads you through an interactive
|
||||||
review session.
|
review session.
|
||||||
|
|
||||||
|
If Tasksh is invoked with command line arguments, those are passed straight
|
||||||
|
through to taskwarrior.
|
||||||
|
|
||||||
Tasksh supports all recent versions of Taskwarrior.
|
Tasksh supports all recent versions of Taskwarrior.
|
||||||
|
|
||||||
.SH COMMANDS
|
.SH COMMANDS
|
||||||
|
|
83
src/main.cpp
83
src/main.cpp
|
@ -93,8 +93,7 @@ const std::string getResponse (const std::string& prompt)
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
static const std::string get_response ()
|
||||||
static int commandLoop (bool autoClear)
|
|
||||||
{
|
{
|
||||||
// Compose the prompt.
|
// Compose the prompt.
|
||||||
auto prompt = promptCompose ();
|
auto prompt = promptCompose ();
|
||||||
|
@ -102,6 +101,12 @@ static int commandLoop (bool autoClear)
|
||||||
// Display prompt, get input.
|
// Display prompt, get input.
|
||||||
auto command = getResponse (prompt);
|
auto command = getResponse (prompt);
|
||||||
|
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
static int commandLoop (std::string command, bool autoClear)
|
||||||
|
{
|
||||||
// Obey Taskwarrior's rc.tasksh.autoclear.
|
// Obey Taskwarrior's rc.tasksh.autoclear.
|
||||||
if (autoClear)
|
if (autoClear)
|
||||||
std::cout << "\033[2J\033[0;0H";
|
std::cout << "\033[2J\033[0;0H";
|
||||||
|
@ -144,52 +149,82 @@ static int commandLoop (bool autoClear)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool should_auto_clear()
|
||||||
|
{
|
||||||
|
bool autoClear = false;
|
||||||
|
std::string input;
|
||||||
|
std::string output;
|
||||||
|
execute ("task", {"_get", "rc.tasksh.autoclear"}, input, output);
|
||||||
|
output = lowerCase (output);
|
||||||
|
autoClear = (output == "true\n" ||
|
||||||
|
output == "1\n" ||
|
||||||
|
output == "y\n" ||
|
||||||
|
output == "yes\n" ||
|
||||||
|
output == "on\n");
|
||||||
|
|
||||||
|
return autoClear;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int main (int argc, const char** argv)
|
int main (int argc, const char** argv)
|
||||||
{
|
{
|
||||||
|
std::string command = "";
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
|
||||||
// Lightweight version checking that doesn't require initialization or any I/O.
|
// Lightweight version checking that doesn't require initialization or any I/O.
|
||||||
if (argc == 2 && !strcmp (argv[1], "--version"))
|
if (argc == 2 && !strcmp (argv[1], "--version"))
|
||||||
{
|
{
|
||||||
std::cout << VERSION << "\n";
|
std::cout << VERSION << "\n";
|
||||||
|
|
||||||
|
// Returning -1 drops out of the command loop, but gets translated to 0 here,
|
||||||
|
// so that there is a clean way to exit.
|
||||||
|
return status == -1 ? 0 : status;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (isatty (fileno (stdin)))
|
||||||
|
welcome ();
|
||||||
|
|
||||||
|
// Process anything given as command-line arguments.
|
||||||
|
if (argc > 1)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Get the Taskwarrior rc.tasksh.autoclear Boolean setting.
|
std::string cmd;
|
||||||
bool autoClear = false;
|
for (int i = 1; i < argc; i++)
|
||||||
std::string input;
|
{
|
||||||
std::string output;
|
std::string cmd_str (argv[i]);
|
||||||
execute ("task", {"_get", "rc.tasksh.autoclear"}, input, output);
|
command += " " + cmd_str;
|
||||||
output = lowerCase (output);
|
}
|
||||||
autoClear = (output == "true\n" ||
|
status = commandLoop (command, should_auto_clear ());
|
||||||
output == "1\n" ||
|
|
||||||
output == "y\n" ||
|
|
||||||
output == "yes\n" ||
|
|
||||||
output == "on\n");
|
|
||||||
|
|
||||||
if (isatty (fileno (stdin)))
|
|
||||||
welcome ();
|
|
||||||
|
|
||||||
while ((status = commandLoop (autoClear)) == 0)
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (const std::string& error)
|
catch (const std::string& error)
|
||||||
{
|
{
|
||||||
std::cerr << error << "\n";
|
std::cerr << error << "\n";
|
||||||
status = -1;
|
status = -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
catch (...)
|
try
|
||||||
|
{
|
||||||
|
while (status == 0)
|
||||||
{
|
{
|
||||||
std::cerr << "Unknown error." << "\n";
|
command = get_response ();
|
||||||
status = -2;
|
status = commandLoop (command, should_auto_clear ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
catch (const std::string& error)
|
||||||
|
{
|
||||||
|
std::cerr << error << "\n";
|
||||||
|
status = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
std::cerr << "Unknown error." << "\n";
|
||||||
|
status = -2;
|
||||||
|
}
|
||||||
|
|
||||||
// Returning -1 drops out of the command loop, but gets translated to 0 here,
|
// Returning -1 drops out of the command loop, but gets translated to 0 here,
|
||||||
// so that there is a clean way to exit.
|
// so that there is a clean way to exit.
|
||||||
return status == -1 ? 0 : status;
|
return status == -1 ? 0 : status;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue