- Now allows rc:<file> override of ~/.taskrc file.

This commit is contained in:
Paul Beckingham 2008-06-25 01:29:42 -04:00
parent 5d158d752d
commit 1ef7b0c43a
5 changed files with 195 additions and 119 deletions

View file

@ -11,10 +11,12 @@ represents a feature release, and the Z represents a patch.
- Dependencies
- Recurring tasks
1.4.0 ()
+ "task undelete" can now undelete erroneously deleted tasks, provided no
reports have been run (and therefore TDB::gc run)
+ 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 underlined table headers when color is turned off

View file

@ -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:...
-------------------------
@ -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
----------------

View file

@ -39,7 +39,7 @@
<p>
Download the
<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>
@ -51,6 +51,8 @@
<li>Added "task undelete" feature to restore a (very) recently deleted
task
<li>Added averages to the "task history" report
<li>Added support for rc:&lt;file&gt; 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 table headers are underlined when color is turned off
</ul>
@ -711,6 +713,65 @@ ID Project Pri Description
all the current configuration settings, as read from the .taskrc
file.
</p>
<strong>% task rc:&lt;file&gt; ...</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 &lt;id&gt; 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>
<br />
@ -756,42 +817,6 @@ ID Project Pri Description
delimiter between an attribute name and its value. Currently there
is no workaround for this.
</p>
<strong>% task &lt;id&gt; 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>
<br />

View file

@ -346,6 +346,11 @@ void parse (
for (size_t i = 0; i < args.size (); ++i)
{
std::string arg (args[i]);
// Ignore any argument that is "rc:...", because that is the command line
// specified rc file.
if (arg.substr (0, 3) != "rc:")
{
size_t colon; // Pointer to colon in argument.
std::string from;
std::string to;
@ -395,6 +400,7 @@ void parse (
else
descCandidate += std::string (arg) + " ";
}
}
if (validDescription (descCandidate))
task.setDescription (descCandidate);

View file

@ -45,7 +45,7 @@
#endif
////////////////////////////////////////////////////////////////////////////////
void shortUsage (Config& conf)
static void shortUsage (Config& conf)
{
Table table;
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);
@ -210,6 +210,7 @@ void longUsage (Config& conf)
<< " due: Due date" << "\n"
<< " fg: Foreground color" << "\n"
<< " bg: Background color" << "\n"
<< " rc: Alternate .taskrc file" << "\n"
<< "\n"
<< "Any command or attribute name may be abbreviated if still unique:" << "\n"
<< " task list project:Home" << "\n"
@ -224,6 +225,32 @@ void longUsage (Config& conf)
<< 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)
{
@ -242,13 +269,7 @@ int main (int argc, char** argv)
// Load the config file from the home directory. If the file cannot be
// found, offer to create a sample one.
Config conf;
struct passwd* pw = getpwuid (getuid ());
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);
loadConfFile (argc, argv, conf);
TDB tdb;
tdb.dataDirectory (conf.get ("data.location"));