mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-19 19:03:07 +02:00
- Now allows rc:<file> override of ~/.taskrc file.
This commit is contained in:
parent
5d158d752d
commit
1ef7b0c43a
5 changed files with 195 additions and 119 deletions
|
@ -11,10 +11,12 @@ represents a feature release, and the Z represents a patch.
|
||||||
- Dependencies
|
- Dependencies
|
||||||
- Recurring tasks
|
- Recurring tasks
|
||||||
|
|
||||||
|
|
||||||
1.4.0 ()
|
1.4.0 ()
|
||||||
+ "task undelete" can now undelete erroneously deleted tasks, provided no
|
+ "task undelete" can now undelete erroneously deleted tasks, provided no
|
||||||
reports have been run (and therefore TDB::gc run)
|
reports have been run (and therefore TDB::gc run)
|
||||||
+ Added averages to the "task history" report
|
+ Added averages to the "task history" report
|
||||||
|
+ Added ability to override ~/.taskrc with rc:<file>
|
||||||
+ Bug: Fixed where Esc[0m sequences were being emitted for no good reason
|
+ Bug: Fixed where Esc[0m sequences were being emitted for no good reason
|
||||||
+ Bug: Fixed underlined table headers when color is turned off
|
+ Bug: Fixed underlined table headers when color is turned off
|
||||||
|
|
||||||
|
|
88
TUTORIAL
88
TUTORIAL
|
@ -576,39 +576,6 @@ with no arguments will generate a help message that lists all these commands.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Interacting with the Shell
|
|
||||||
--------------------------
|
|
||||||
|
|
||||||
Certain characters are interpreted by the shell. For example, the "&". If
|
|
||||||
you wish to include the & in a task description, you need to escape it, so
|
|
||||||
the shell doesn't interpret it. For example:
|
|
||||||
|
|
||||||
% task add Buy bread & milk
|
|
||||||
|
|
||||||
This command is an error because of the &. The shell will consider this to
|
|
||||||
be two commands:
|
|
||||||
|
|
||||||
% task add Buy bread &
|
|
||||||
% milk
|
|
||||||
|
|
||||||
The shell treats the & character as an indicator that the command is complete
|
|
||||||
and should be run in the background. Then the shell considers "milk" to be a
|
|
||||||
command all by itself. Which it is not. One way to get around this is to
|
|
||||||
individually escape the & character:
|
|
||||||
|
|
||||||
% task add Buy bread \& milk
|
|
||||||
|
|
||||||
Another is to quote the entire description, with either ' or " characters:
|
|
||||||
|
|
||||||
% task add "Buy bread & milk"
|
|
||||||
|
|
||||||
Task itself interprets the commands, and it too can make mistakes. For
|
|
||||||
example, any colon : character will be interpreted by task as a delimiter
|
|
||||||
between an attribute name and its value. Currently there is no workaround
|
|
||||||
for this.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
% task <id> fg:... bg:...
|
% task <id> fg:... bg:...
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
|
@ -645,6 +612,61 @@ Interacting with the Shell
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
% task rc:<file> ...
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
By specifying rc:<file>, it is possible to force task to use an alternate
|
||||||
|
.taskrc file. By default, task looks in your home directory, so these two
|
||||||
|
commands are essentially identical:
|
||||||
|
|
||||||
|
% task list
|
||||||
|
% task rc:~/.taskrc list
|
||||||
|
|
||||||
|
What this override allows, is the possibility of keeping your task lists
|
||||||
|
completely separate, say for work and home. This can be accomplished with
|
||||||
|
the following commands (valid for bash):
|
||||||
|
|
||||||
|
% alias htask="task rc:/home/me/.taskrc_home"
|
||||||
|
% alias wtask="task rc:/home/me/.taskrc_work"
|
||||||
|
% htask list
|
||||||
|
...
|
||||||
|
% wtask list
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Interacting with the Shell
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
Certain characters are interpreted by the shell. For example, the "&". If
|
||||||
|
you wish to include the & in a task description, you need to escape it, so
|
||||||
|
the shell doesn't interpret it. For example:
|
||||||
|
|
||||||
|
% task add Buy bread & milk
|
||||||
|
|
||||||
|
This command is an error because of the &. The shell will consider this to
|
||||||
|
be two commands:
|
||||||
|
|
||||||
|
% task add Buy bread &
|
||||||
|
% milk
|
||||||
|
|
||||||
|
The shell treats the & character as an indicator that the command is complete
|
||||||
|
and should be run in the background. Then the shell considers "milk" to be a
|
||||||
|
command all by itself. Which it is not. One way to get around this is to
|
||||||
|
individually escape the & character:
|
||||||
|
|
||||||
|
% task add Buy bread \& milk
|
||||||
|
|
||||||
|
Another is to quote the entire description, with either ' or " characters:
|
||||||
|
|
||||||
|
% task add "Buy bread & milk"
|
||||||
|
|
||||||
|
Task itself interprets the commands, and it too can make mistakes. For
|
||||||
|
example, any colon : character will be interpreted by task as a delimiter
|
||||||
|
between an attribute name and its value. Currently there is no workaround
|
||||||
|
for this.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Configuring Task
|
Configuring Task
|
||||||
----------------
|
----------------
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
<p>
|
<p>
|
||||||
Download the
|
Download the
|
||||||
<a href="http://www.beckingham.net/task-1.4.0.tar.gz">latest version</a>
|
<a href="http://www.beckingham.net/task-1.4.0.tar.gz">latest version</a>
|
||||||
of the task source code (1.4.0, ????????????????????????????????????????????????).
|
of the task source code (1.4.0, ????????????????????).
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
@ -51,6 +51,8 @@
|
||||||
<li>Added "task undelete" feature to restore a (very) recently deleted
|
<li>Added "task undelete" feature to restore a (very) recently deleted
|
||||||
task
|
task
|
||||||
<li>Added averages to the "task history" report
|
<li>Added averages to the "task history" report
|
||||||
|
<li>Added support for rc:<file> to allow override of the default
|
||||||
|
~/.taskrc file
|
||||||
<li>Fixed bug where Esc[0m sequences were being emitted for no good reason
|
<li>Fixed bug where Esc[0m sequences were being emitted for no good reason
|
||||||
<li>Fixed bug where table headers are underlined when color is turned off
|
<li>Fixed bug where table headers are underlined when color is turned off
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -711,6 +713,65 @@ ID Project Pri Description
|
||||||
all the current configuration settings, as read from the .taskrc
|
all the current configuration settings, as read from the .taskrc
|
||||||
file.
|
file.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<strong>% task rc:<file> ...</strong>
|
||||||
|
<p>
|
||||||
|
By specifying rc:<file>, it is possible to force task to use an alternate
|
||||||
|
.taskrc file. By default, task looks in your home directory, so these two
|
||||||
|
commands are essentially identical:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre><code>% task list
|
||||||
|
% task rc:~/.taskrc list</code></pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
What this override allows, is the possibility of keeping your task lists
|
||||||
|
completely separate, say for work and home. This can be accomplished with
|
||||||
|
the following commands (valid for bash):
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre><code>% alias htask="task rc:/home/me/.taskrc_home"
|
||||||
|
% alias wtask="task rc:/home/me/.taskrc_work"
|
||||||
|
% htask list
|
||||||
|
...
|
||||||
|
% wtask list
|
||||||
|
...</code></pre>
|
||||||
|
|
||||||
|
<strong>% task <id> fg:... bg:...</strong>
|
||||||
|
<p>
|
||||||
|
Not strictly a command, the setting of the fg and bg (foreground
|
||||||
|
and background) attributes determines the colors used to represent
|
||||||
|
the task. Valid foreground colors are:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre><code> bold underline bold_underline
|
||||||
|
black bold_black underline_black bold_underline_black
|
||||||
|
red bold_red underline_red bold_underline_red
|
||||||
|
green bold_green underline_green bold_underline_green
|
||||||
|
yellow bold_yellow underline_yellow bold_underline_yellow
|
||||||
|
blue bold_blue underline_blue bold_underline_blue
|
||||||
|
magenta bold_magenta underline_magenta bold_underline_magenta
|
||||||
|
cyan bold_cyan underline_cyan bold_underline_cyan
|
||||||
|
white bold_white underline_white bold_underline_white</code></pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Note that these are not just colors, but combinations of colors and
|
||||||
|
attributes. Valid background colors are:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre><code>on_black on_bright_black
|
||||||
|
on_red on_bright_red
|
||||||
|
on_green on_bright_green
|
||||||
|
on_yellow on_bright_yellow
|
||||||
|
on_blue on_bright_blue
|
||||||
|
on_magenta on_bright_magenta
|
||||||
|
on_cyan on_bright_cyan
|
||||||
|
on_white on_bright_white</code></pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Note also that this capability does depend on whether your terminal
|
||||||
|
program can display these colors.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
@ -756,42 +817,6 @@ ID Project Pri Description
|
||||||
delimiter between an attribute name and its value. Currently there
|
delimiter between an attribute name and its value. Currently there
|
||||||
is no workaround for this.
|
is no workaround for this.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<strong>% task <id> fg:... bg:...</strong>
|
|
||||||
<p>
|
|
||||||
Not strictly a command, the setting of the fg and bg (foreground
|
|
||||||
and background) attributes determines the colors used to represent
|
|
||||||
the task. Valid foreground colors are:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<pre><code> bold underline bold_underline
|
|
||||||
black bold_black underline_black bold_underline_black
|
|
||||||
red bold_red underline_red bold_underline_red
|
|
||||||
green bold_green underline_green bold_underline_green
|
|
||||||
yellow bold_yellow underline_yellow bold_underline_yellow
|
|
||||||
blue bold_blue underline_blue bold_underline_blue
|
|
||||||
magenta bold_magenta underline_magenta bold_underline_magenta
|
|
||||||
cyan bold_cyan underline_cyan bold_underline_cyan
|
|
||||||
white bold_white underline_white bold_underline_white</code></pre>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Note that these are not just colors, but combinations of colors and
|
|
||||||
attributes. Valid background colors are:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<pre><code>on_black on_bright_black
|
|
||||||
on_red on_bright_red
|
|
||||||
on_green on_bright_green
|
|
||||||
on_yellow on_bright_yellow
|
|
||||||
on_blue on_bright_blue
|
|
||||||
on_magenta on_bright_magenta
|
|
||||||
on_cyan on_bright_cyan
|
|
||||||
on_white on_bright_white</code></pre>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Note also that this capability does depend on whether your terminal
|
|
||||||
program can display these colors.
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -346,54 +346,60 @@ void parse (
|
||||||
for (size_t i = 0; i < args.size (); ++i)
|
for (size_t i = 0; i < args.size (); ++i)
|
||||||
{
|
{
|
||||||
std::string arg (args[i]);
|
std::string arg (args[i]);
|
||||||
size_t colon; // Pointer to colon in argument.
|
|
||||||
std::string from;
|
|
||||||
std::string to;
|
|
||||||
|
|
||||||
// An id is the first argument found that contains all digits.
|
// Ignore any argument that is "rc:...", because that is the command line
|
||||||
if (command != "add" && // "add" doesn't require an ID
|
// specified rc file.
|
||||||
task.getId () == 0 &&
|
if (arg.substr (0, 3) != "rc:")
|
||||||
validId (arg))
|
|
||||||
task.setId (::atoi (arg.c_str ()));
|
|
||||||
|
|
||||||
// Tags begin with + or - and contain arbitrary text.
|
|
||||||
else if (validTag (arg))
|
|
||||||
{
|
{
|
||||||
if (arg[0] == '+')
|
size_t colon; // Pointer to colon in argument.
|
||||||
task.addTag (arg.substr (1, std::string::npos));
|
std::string from;
|
||||||
else if (arg[0] == '-')
|
std::string to;
|
||||||
task.addRemoveTag (arg.substr (1, std::string::npos));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attributes contain a constant string followed by a colon, followed by a
|
// An id is the first argument found that contains all digits.
|
||||||
// value.
|
if (command != "add" && // "add" doesn't require an ID
|
||||||
else if ((colon = arg.find (":")) != std::string::npos)
|
task.getId () == 0 &&
|
||||||
{
|
validId (arg))
|
||||||
std::string name = arg.substr (0, colon);
|
task.setId (::atoi (arg.c_str ()));
|
||||||
std::string value = arg.substr (colon + 1, std::string::npos);
|
|
||||||
|
|
||||||
if (validAttribute (name, value, conf))
|
// Tags begin with + or - and contain arbitrary text.
|
||||||
task.setAttribute (name, value);
|
else if (validTag (arg))
|
||||||
}
|
{
|
||||||
|
if (arg[0] == '+')
|
||||||
|
task.addTag (arg.substr (1, std::string::npos));
|
||||||
|
else if (arg[0] == '-')
|
||||||
|
task.addRemoveTag (arg.substr (1, std::string::npos));
|
||||||
|
}
|
||||||
|
|
||||||
// Substitution of description text.
|
// Attributes contain a constant string followed by a colon, followed by a
|
||||||
else if (validSubstitution (arg, from, to))
|
// value.
|
||||||
{
|
else if ((colon = arg.find (":")) != std::string::npos)
|
||||||
task.setSubstitution (from, to);
|
{
|
||||||
}
|
std::string name = arg.substr (0, colon);
|
||||||
|
std::string value = arg.substr (colon + 1, std::string::npos);
|
||||||
|
|
||||||
// Command.
|
if (validAttribute (name, value, conf))
|
||||||
else if (command == "")
|
task.setAttribute (name, value);
|
||||||
{
|
}
|
||||||
if (!isCommand (arg))
|
|
||||||
|
// Substitution of description text.
|
||||||
|
else if (validSubstitution (arg, from, to))
|
||||||
|
{
|
||||||
|
task.setSubstitution (from, to);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Command.
|
||||||
|
else if (command == "")
|
||||||
|
{
|
||||||
|
if (!isCommand (arg))
|
||||||
|
descCandidate += std::string (arg) + " ";
|
||||||
|
else if (validCommand (arg))
|
||||||
|
command = arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Anything else is just considered description.
|
||||||
|
else
|
||||||
descCandidate += std::string (arg) + " ";
|
descCandidate += std::string (arg) + " ";
|
||||||
else if (validCommand (arg))
|
|
||||||
command = arg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Anything else is just considered description.
|
|
||||||
else
|
|
||||||
descCandidate += std::string (arg) + " ";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validDescription (descCandidate))
|
if (validDescription (descCandidate))
|
||||||
|
|
39
src/task.cpp
39
src/task.cpp
|
@ -45,7 +45,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void shortUsage (Config& conf)
|
static void shortUsage (Config& conf)
|
||||||
{
|
{
|
||||||
Table table;
|
Table table;
|
||||||
int width = conf.get ("defaultwidth", 80);
|
int width = conf.get ("defaultwidth", 80);
|
||||||
|
@ -193,7 +193,7 @@ void shortUsage (Config& conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void longUsage (Config& conf)
|
static void longUsage (Config& conf)
|
||||||
{
|
{
|
||||||
shortUsage (conf);
|
shortUsage (conf);
|
||||||
|
|
||||||
|
@ -210,6 +210,7 @@ void longUsage (Config& conf)
|
||||||
<< " due: Due date" << "\n"
|
<< " due: Due date" << "\n"
|
||||||
<< " fg: Foreground color" << "\n"
|
<< " fg: Foreground color" << "\n"
|
||||||
<< " bg: Background color" << "\n"
|
<< " bg: Background color" << "\n"
|
||||||
|
<< " rc: Alternate .taskrc file" << "\n"
|
||||||
<< "\n"
|
<< "\n"
|
||||||
<< "Any command or attribute name may be abbreviated if still unique:" << "\n"
|
<< "Any command or attribute name may be abbreviated if still unique:" << "\n"
|
||||||
<< " task list project:Home" << "\n"
|
<< " task list project:Home" << "\n"
|
||||||
|
@ -224,6 +225,32 @@ void longUsage (Config& conf)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void loadConfFile (int argc, char** argv, Config& conf)
|
||||||
|
{
|
||||||
|
for (int i = 1; i < argc; ++i)
|
||||||
|
{
|
||||||
|
if (! strncmp (argv[i], "rc:", 3))
|
||||||
|
{
|
||||||
|
if (! access (&(argv[i][3]), F_OK))
|
||||||
|
{
|
||||||
|
std::string file = &(argv[i][3]);
|
||||||
|
conf.load (file);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw std::string ("Could not read configuration file '") + &(argv[i][3]) + "'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct passwd* pw = getpwuid (getuid ());
|
||||||
|
if (!pw)
|
||||||
|
throw std::string ("Could not read home directory from passwd file.");
|
||||||
|
|
||||||
|
std::string file = pw->pw_dir;
|
||||||
|
conf.createDefault (file);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int main (int argc, char** argv)
|
int main (int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
@ -242,13 +269,7 @@ int main (int argc, char** argv)
|
||||||
// Load the config file from the home directory. If the file cannot be
|
// Load the config file from the home directory. If the file cannot be
|
||||||
// found, offer to create a sample one.
|
// found, offer to create a sample one.
|
||||||
Config conf;
|
Config conf;
|
||||||
struct passwd* pw = getpwuid (getuid ());
|
loadConfFile (argc, argv, conf);
|
||||||
if (!pw)
|
|
||||||
throw std::string ("Could not read home directory from passwd file.");
|
|
||||||
|
|
||||||
// Create a default config file and data directory if necessary.
|
|
||||||
std::string home = pw->pw_dir;
|
|
||||||
conf.createDefault (home);
|
|
||||||
|
|
||||||
TDB tdb;
|
TDB tdb;
|
||||||
tdb.dataDirectory (conf.get ("data.location"));
|
tdb.dataDirectory (conf.get ("data.location"));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue