mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-28 04:27:20 +02:00
Enhancement - Edit command
- Added more fields to the edit command. - Added a more useful slurp implementation. - Updated advanced.html with directions on use.
This commit is contained in:
parent
407ef39c54
commit
6762af8ffd
4 changed files with 76 additions and 24 deletions
|
@ -426,6 +426,22 @@ ID Project Pri Description
|
||||||
command.
|
command.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<strong>% task <id> edit</strong>
|
||||||
|
<p>
|
||||||
|
This command allows you to use your text editor to edit all aspects
|
||||||
|
of a task. The specified task will be written to a file, and your
|
||||||
|
text editor will be invoked. If you modify the task in the text
|
||||||
|
editor, task will update accordingly.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Task will first check to see if you have defined a text editor
|
||||||
|
in the TASK_EDITOR environment variable. If not, task will
|
||||||
|
check to see if you defined a text editor in the VISUAL
|
||||||
|
environment variable. If not task will check to see if you
|
||||||
|
defined a text editor in the EDITOR environment variable.
|
||||||
|
If all those fail, task launches vi.
|
||||||
|
</p>
|
||||||
|
|
||||||
<strong>% task <id> fg:... bg:...</strong>
|
<strong>% task <id> fg:... bg:...</strong>
|
||||||
<p>
|
<p>
|
||||||
Not strictly a command, the setting of the fg and bg (foreground
|
Not strictly a command, the setting of the fg and bg (foreground
|
||||||
|
|
|
@ -860,6 +860,18 @@ std::string handleDuplicate (TDB& tdb, T& task, Config& conf)
|
||||||
return out.str ();
|
return out.str ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
static const char* leftDelim = "<<";
|
||||||
|
static const char* rightDelim = ">>";
|
||||||
|
static std::string findValue (const std::string& text, const std::string& name)
|
||||||
|
{
|
||||||
|
// Look for /^\s+name:\s+<<(.*)>>/
|
||||||
|
// Extract
|
||||||
|
// Trim
|
||||||
|
// Join
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Introducing the Silver Bullet. This feature is the catch-all fixative for
|
// Introducing the Silver Bullet. This feature is the catch-all fixative for
|
||||||
// various other ills. This is like opening up the hood and going in with a
|
// various other ills. This is like opening up the hood and going in with a
|
||||||
|
@ -878,47 +890,45 @@ std::string handleEdit (TDB& tdb, T& task, Config& conf)
|
||||||
if (access (dataLocation.c_str (), X_OK))
|
if (access (dataLocation.c_str (), X_OK))
|
||||||
throw std::string ("Your data.location directory is not writable.");
|
throw std::string ("Your data.location directory is not writable.");
|
||||||
|
|
||||||
// TODO Create a temp file name in data.location.
|
// Create a temp file name in data.location.
|
||||||
std::stringstream pattern;
|
std::stringstream pattern;
|
||||||
pattern << dataLocation
|
pattern << dataLocation << "/task." << seq->getId () << ".XXXXXX";
|
||||||
<< "/task."
|
|
||||||
<< seq->getId ()
|
|
||||||
<< ".XXXXXX";
|
|
||||||
std::cout << "# pattern=" << pattern << std::endl;
|
|
||||||
char cpattern [PATH_MAX];
|
char cpattern [PATH_MAX];
|
||||||
strcpy (cpattern, pattern.str ().c_str ());
|
strcpy (cpattern, pattern.str ().c_str ());
|
||||||
|
|
||||||
char* file = mktemp (cpattern);
|
char* file = mktemp (cpattern);
|
||||||
std::cout << "# file=" << file << std::endl;
|
|
||||||
|
|
||||||
// TODO Format the contents, T -> text.
|
// TODO Format the contents, T -> text.
|
||||||
std::stringstream before;
|
std::stringstream before;
|
||||||
before << "# Edit only the items within the chevrons << >>. "
|
before << "# Edit only the items within the marks "
|
||||||
|
<< leftDelim << " " << rightDelim << "."
|
||||||
<< "All other edits will be ignored." << std::endl
|
<< "All other edits will be ignored." << std::endl
|
||||||
<< "ID: " << seq->getId () << std::endl
|
<< "ID: " << seq->getId () << std::endl
|
||||||
<< "Project: <<" << seq->getAttribute ("project") << ">>" << std::endl
|
<< "Project: " << leftDelim << seq->getAttribute ("project") << rightDelim << std::endl
|
||||||
<< "Priority: <<" << seq->getAttribute ("priority") << ">>" << std::endl
|
<< "Priority: " << leftDelim << seq->getAttribute ("priority") << rightDelim << std::endl
|
||||||
<< "Description: <<" << seq->getDescription () << ">>" << std::endl;
|
<< "Description: " << leftDelim << seq->getDescription () << rightDelim << std::endl;
|
||||||
|
|
||||||
// Write to file.
|
// Write to file.
|
||||||
spit (file, before.str ());
|
spit (file, before.str ());
|
||||||
|
|
||||||
// TODO Determine correct editor: $EDITOR > $VISUAL > vi
|
// Determine correct editor: $TASK_EDITOR > $VISUAL > $EDITOR > vi
|
||||||
std::string editor = "/usr/bin/vi";
|
const char* editor = getenv ("TASK_EDITOR");
|
||||||
|
if (!editor) editor = getenv ("VISUAL");
|
||||||
|
if (!editor) editor = getenv ("EDITOR");
|
||||||
|
if (!editor) editor = "vi";
|
||||||
|
|
||||||
// system ("$EDITOR $file");
|
// Launch the editor.
|
||||||
std::string command = editor + " " + file;
|
std::string command = editor;
|
||||||
|
command += " ";
|
||||||
|
command += file;
|
||||||
system (command.c_str ());
|
system (command.c_str ());
|
||||||
|
|
||||||
// Slurp file.
|
// Slurp file.
|
||||||
std::vector <std::string> after;
|
std::string after;
|
||||||
slurp (file, after, true);
|
slurp (file, after, true);
|
||||||
|
|
||||||
// TODO Parse file, text -> T.
|
seq->setAttribute ("Project", findValue (after, "Project"));
|
||||||
foreach (line, after)
|
seq->setAttribute ("Priority", findValue (after, "Priority"));
|
||||||
{
|
seq->setDescription ( findValue (after, "Description"));
|
||||||
// TODO Handle each type of line.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Modify task.
|
// Modify task.
|
||||||
tdb.modifyT (*seq);
|
tdb.modifyT (*seq);
|
||||||
|
|
|
@ -152,6 +152,7 @@ std::string expandPath (const std::string&);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool slurp (const std::string&, std::vector <std::string>&, bool trimLines = false);
|
bool slurp (const std::string&, std::vector <std::string>&, bool trimLines = false);
|
||||||
|
bool slurp (const std::string&, std::string&, bool trimLines = false);
|
||||||
void spit (const std::string&, const std::string&);
|
void spit (const std::string&, const std::string&);
|
||||||
|
|
||||||
// rules.cpp
|
// rules.cpp
|
||||||
|
|
25
src/util.cpp
25
src/util.cpp
|
@ -429,6 +429,31 @@ bool slurp (
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool slurp (
|
||||||
|
const std::string& file,
|
||||||
|
std::string& contents,
|
||||||
|
bool trimLines /* = false */)
|
||||||
|
{
|
||||||
|
contents = "";
|
||||||
|
|
||||||
|
std::ifstream in (file.c_str ());
|
||||||
|
if (in.good ())
|
||||||
|
{
|
||||||
|
std::string line;
|
||||||
|
while (getline (in, line))
|
||||||
|
{
|
||||||
|
if (trimLines) line = trim (line);
|
||||||
|
contents += line;
|
||||||
|
}
|
||||||
|
|
||||||
|
in.close ();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void spit (const std::string& file, const std::string& contents)
|
void spit (const std::string& file, const std::string& contents)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue