Support relative include for themes in taskrc

This commit is contained in:
oxalica 2021-04-24 02:12:00 +08:00 committed by Tomas Babej
parent 3672ed0c1b
commit 2cb8f1d5ea
4 changed files with 26 additions and 24 deletions

View file

@ -236,11 +236,10 @@ include other files into the .taskrc file, different sets of color rules can
be included. be included.
To get a good idea of what a color theme looks like, try adding this entry to To get a good idea of what a color theme looks like, try adding this entry to
your .taskrc file (note that your installation may use a slightly different path your .taskrc file:
from the example):
.RS .RS
include ${CMAKE_INSTALL_PREFIX}/${TASK_RCDIR}/dark-256.theme include dark-256.theme
.RE .RE
You can use any of the standard Taskwarrior themes: You can use any of the standard Taskwarrior themes:

View file

@ -85,7 +85,8 @@ include <file>
There may be whitespace around 'include' and <file>. The file may be an There may be whitespace around 'include' and <file>. The file may be an
absolute or relative path, and the special character '~' is expanded to mean absolute or relative path, and the special character '~' is expanded to mean
$HOME. $HOME. If relative path is specified, it will be searched in installation
directory of configuration files, which contains themes.
The entry must be on a single line, no continuations. The entry must be on a single line, no continuations.
.RS .RS
@ -152,9 +153,9 @@ ones containing just the relevant configuration data like colors, etc.
There are two excellent uses of includes in your .taskrc, shown here: There are two excellent uses of includes in your .taskrc, shown here:
.RS .RS
include ${CMAKE_INSTALL_PREFIX}/${TASK_RCDIR}/holidays.en-US.rc include holidays.en-US.rc
.br .br
include ${CMAKE_INSTALL_PREFIX}/${TASK_RCDIR}/dark-16.theme include dark-16.theme
.RE .RE
This includes two standard files that are distributed with Taskwarrior, which This includes two standard files that are distributed with Taskwarrior, which
@ -818,7 +819,7 @@ be included like this:
.RS .RS
.RS .RS
.br .br
include ${CMAKE_INSTALL_PREFIX}/${TASK_RCDIR}/holidays.en-US.rc include holidays.en-US.rc
.RE .RE
.RE .RE

View file

@ -440,6 +440,8 @@ int Context::initialize (int argc, const char** argv)
int rc = 0; int rc = 0;
home_dir = getenv ("HOME"); home_dir = getenv ("HOME");
std::vector <std::string> searchPaths { TASK_RCDIR };
try try
{ {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
@ -494,8 +496,8 @@ int Context::initialize (int argc, const char** argv)
// Artificial scope for timing purposes. // Artificial scope for timing purposes.
{ {
Timer timer; Timer timer;
config.parse (configurationDefaults); config.parse (configurationDefaults, 1, searchPaths);
config.load (rc_file._data); config.load (rc_file._data, 1, searchPaths);
debugTiming (format ("Config::load ({1})", rc_file._data), timer); debugTiming (format ("Config::load ({1})", rc_file._data), timer);
} }
@ -1191,20 +1193,20 @@ void Context::createDefaultConfig ()
<< "\n#data.location=~/.local/share/task\n" << "\n#data.location=~/.local/share/task\n"
<< "#hooks.location=~/.config/task/hooks\n" << "#hooks.location=~/.config/task/hooks\n"
<< "\n# Color theme (uncomment one to use)\n" << "\n# Color theme (uncomment one to use)\n"
<< "#include " << TASK_RCDIR << "/light-16.theme\n" << "#include light-16.theme\n"
<< "#include " << TASK_RCDIR << "/light-256.theme\n" << "#include light-256.theme\n"
<< "#include " << TASK_RCDIR << "/dark-16.theme\n" << "#include dark-16.theme\n"
<< "#include " << TASK_RCDIR << "/dark-256.theme\n" << "#include dark-256.theme\n"
<< "#include " << TASK_RCDIR << "/dark-red-256.theme\n" << "#include dark-red-256.theme\n"
<< "#include " << TASK_RCDIR << "/dark-green-256.theme\n" << "#include dark-green-256.theme\n"
<< "#include " << TASK_RCDIR << "/dark-blue-256.theme\n" << "#include dark-blue-256.theme\n"
<< "#include " << TASK_RCDIR << "/dark-violets-256.theme\n" << "#include dark-violets-256.theme\n"
<< "#include " << TASK_RCDIR << "/dark-yellow-green.theme\n" << "#include dark-yellow-green.theme\n"
<< "#include " << TASK_RCDIR << "/dark-gray-256.theme\n" << "#include dark-gray-256.theme\n"
<< "#include " << TASK_RCDIR << "/dark-gray-blue-256.theme\n" << "#include dark-gray-blue-256.theme\n"
<< "#include " << TASK_RCDIR << "/solarized-dark-256.theme\n" << "#include solarized-dark-256.theme\n"
<< "#include " << TASK_RCDIR << "/solarized-light-256.theme\n" << "#include solarized-light-256.theme\n"
<< "#include " << TASK_RCDIR << "/no-color.theme\n" << "#include no-color.theme\n"
<< '\n'; << '\n';
// Write out the new file. // Write out the new file.

@ -1 +1 @@
Subproject commit 9a5f24e2acb38d05afb8f8e316a966dee196a42a Subproject commit b00c80c7a97103551acae7dbe47cf92cc57d308b