diff --git a/src/Context.cpp b/src/Context.cpp index d5c9c1317..c30e3191a 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -395,8 +396,8 @@ int Context::dispatch (std::string &out) return rc; } - if (commands["help"]) - return commands["help"]->execute (out); + assert (commands["help"]); + return commands["help"]->execute (out); return 1; } diff --git a/src/commands/CmdEdit.cpp b/src/commands/CmdEdit.cpp index e827a5de2..01ff0878d 100644 --- a/src/commands/CmdEdit.cpp +++ b/src/commands/CmdEdit.cpp @@ -629,7 +629,6 @@ bool CmdEdit::editFile (Task& task) // Create a temp file name in data.location. std::stringstream file; file << "task." << getpid () << "." << task.id << ".task"; - std::string path = location._data + "/" + file.str (); // Determine the output date format, which uses a hierarchy of definitions. // rc.dateformat.edit @@ -638,10 +637,13 @@ bool CmdEdit::editFile (Task& task) if (dateformat == "") dateformat = context.config.get ("dateformat"); - // Format the contents, T -> text, write to a file. - std::string before = formatTask (task, dateformat); + // Change directory for the editor + char* current_dir = get_current_dir_name (); int ignored = chdir (location._data.c_str ()); ++ignored; // Keep compiler quiet. + + // Format the contents, T -> text, write to a file. + std::string before = formatTask (task, dateformat); File::write (file.str (), before); // Determine correct editor: .taskrc:editor > $VISUAL > $EDITOR > vi @@ -711,6 +713,8 @@ ARE_THESE_REALLY_HARMFUL: // Cleanup. File::remove (file.str ()); + ignored = chdir (current_dir); + free (current_dir); return changes; } diff --git a/src/commands/CmdMerge.cpp b/src/commands/CmdMerge.cpp index def012ad0..81e9d1196 100644 --- a/src/commands/CmdMerge.cpp +++ b/src/commands/CmdMerge.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -131,6 +132,7 @@ int CmdMerge::execute (std::string& output) context.a3.push_back (Arg (uri._data, Arg::cat_literal)); std::string out; + assert (context.commands["push"]); context.commands["push"]->execute (out); } }