diff --git a/ChangeLog b/ChangeLog index 063f7877c..dbf7b11b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,7 @@ due dates, which are no longer relevant to a completed task (thanks to Cory Donnelly). + Fixed bug that was causing the 'completed' report to sort incorrectly. + + Fixed bug #322 which failed to propagate rc overrides to shell commands. ------ old releases ------------------------------ diff --git a/src/Context.cpp b/src/Context.cpp index 1b7ba1072..ed76022ff 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -50,7 +50,8 @@ Context::Context () , tdb () , stringtable () , program ("") -, overrides ("") +, file_override ("") +, var_overrides ("") , cmd () , inShadow (false) { @@ -66,6 +67,7 @@ void Context::initialize (int argc, char** argv) { // Capture the args. for (int i = 0; i < argc; ++i) + { if (i == 0) { program = argv[i]; @@ -76,6 +78,7 @@ void Context::initialize (int argc, char** argv) } else args.push_back (argv[i]); + } initialize (); } @@ -350,13 +353,14 @@ void Context::loadCorrectConfigFile () std::string rc = home + "/.taskrc"; std::string data = home + "/.task"; - // Is there an override for rc? + // Is there an file_override for rc:? foreach (arg, args) { if (*arg == "--") break; else if (arg->substr (0, 3) == "rc:") { + file_override = *arg; rc = arg->substr (3, std::string::npos); home = rc; @@ -380,7 +384,7 @@ void Context::loadCorrectConfigFile () if (config.get ("data.location") != "") data = config.get ("data.location"); - // Is there an override for data? + // Are there any var_overrides for data.location? foreach (arg, args) { if (*arg == "--") @@ -440,7 +444,7 @@ void Context::loadCorrectConfigFile () n.getUntilEOS (value)) { config.set (name, value); - overrides += " " + *arg; + var_overrides += " " + *arg; footnote (std::string ("Configuration override ") + // TODO i18n arg->substr (3, std::string::npos)); } @@ -658,15 +662,21 @@ void Context::parse ( if (parseCmd.command == "" && parseArgs.size () == 0) { // Apply overrides, if any. - std::string defaultCommand = config.get ("default.command") + overrides; + std::string defaultCommand = config.get ("default.command"); if (defaultCommand != "") { + // Add on the overrides. + defaultCommand += " " + file_override + " " + var_overrides; + // Stuff the command line. args.clear (); split (args, defaultCommand, ' '); header ("[task " + defaultCommand + "]"); // Reinitialize the context and recurse. + file_override = ""; + var_overrides = ""; + footnotes.clear (); initialize (); parse (args, cmd, task, sequence, subst, filter); } @@ -691,6 +701,8 @@ void Context::clear () // stringtable.clear (); program = ""; args.clear (); + file_override = ""; + var_overrides = ""; cmd.command = ""; tagAdditions.clear (); tagRemovals.clear (); diff --git a/src/Context.h b/src/Context.h index e903bb8a7..bf56675bc 100644 --- a/src/Context.h +++ b/src/Context.h @@ -83,7 +83,8 @@ public: StringTable stringtable; std::string program; std::vector args; - std::string overrides; + std::string file_override; + std::string var_overrides; Cmd cmd; std::map aliases; std::vector tagAdditions; diff --git a/src/command.cpp b/src/command.cpp index c359171c7..2609d22a9 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -1169,13 +1169,9 @@ void handleShell () << std::endl << std::endl; - // Preserve any special override arguments, and reapply them for each - // shell command. - std::vector special; - foreach (arg, context.args) - if (arg->substr (0, 3) == "rc." || - arg->substr (0, 3) == "rc:") - special.push_back (*arg); + // Make a copy because context.clear will delete them. + std::string permanentOverrides = " " + context.file_override + + " " + context.var_overrides; std::string quit = "quit"; // TODO i18n std::string command; @@ -1187,8 +1183,10 @@ void handleShell () command = ""; std::getline (std::cin, command); - command = trim (command); + std::string decoratedCommand = trim (command + permanentOverrides); + // When looking for the 'quit' command, use 'command', not + // 'decoratedCommand'. if (command.length () > 0 && command.length () <= quit.length () && lowerCase (command) == quit.substr (0, command.length ())) @@ -1202,8 +1200,7 @@ void handleShell () context.clear (); std::vector args; - split (args, command, ' '); - foreach (arg, special) context.args.push_back (*arg); + split (args, decoratedCommand, ' '); foreach (arg, args) context.args.push_back (*arg); context.initialize (); diff --git a/src/text.cpp b/src/text.cpp index d980b7c34..793ebc0f1 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -57,14 +57,16 @@ void wrapText ( void split ( std::vector& results, const std::string& input, - const char delimiter) + const char delimiter, + bool nontrivial /* = true */) { results.clear (); std::string::size_type start = 0; std::string::size_type i; while ((i = input.find (delimiter, start)) != std::string::npos) { - results.push_back (input.substr (start, i - start)); + if (!nontrivial || i != start) + results.push_back (input.substr (start, i - start)); start = i + 1; } @@ -76,7 +78,8 @@ void split ( void split ( std::vector& results, const std::string& input, - const std::string& delimiter) + const std::string& delimiter, + bool nontrivial /* = true */) { results.clear (); std::string::size_type length = delimiter.length (); @@ -85,7 +88,8 @@ void split ( std::string::size_type i; while ((i = input.find (delimiter, start)) != std::string::npos) { - results.push_back (input.substr (start, i - start)); + if (!nontrivial || i != start) + results.push_back (input.substr (start, i - start)); start = i + length; } diff --git a/src/text.h b/src/text.h index 95eb718a7..bb82cb6fa 100644 --- a/src/text.h +++ b/src/text.h @@ -38,8 +38,8 @@ std::string trimRight (const std::string& in, const std::string& t = " "); std::string trim (const std::string& in, const std::string& t = " "); std::string unquoteText (const std::string&); void extractLine (std::string&, std::string&, int); -void split (std::vector&, const std::string&, const char); -void split (std::vector&, const std::string&, const std::string&); +void split (std::vector&, const std::string&, const char, bool nontrivial = true); +void split (std::vector&, const std::string&, const std::string&, bool nontrivial = true); void join (std::string&, const std::string&, const std::vector&); std::string commify (const std::string&); std::string lowerCase (const std::string&);