///////////////////////////////////////////////////////////////////////////
| 1171 | |
| 1172 | //////////////////////////////////////////////////////////////////////////////// |
| 1173 | void Context::createDefaultConfig() { |
| 1174 | // Do we need to create a default rc? |
| 1175 | if (rc_file._data != "" && !rc_file.exists()) { |
| 1176 | // If stdout is not a file, we are probably executing in a completion context and should not |
| 1177 | // prompt (as the user won't see it) or modify the config (as completion functions are typically |
| 1178 | // read-only). |
| 1179 | if (!isatty(STDOUT_FILENO)) { |
| 1180 | throw std::string("Cannot proceed without rc file."); |
| 1181 | } |
| 1182 | |
| 1183 | if (config.getBoolean("confirmation") && |
| 1184 | !confirm(format("A configuration file could not be found in {1}\n\nWould you like a sample " |
| 1185 | "{2} created, so Taskwarrior can proceed?", |
| 1186 | home_dir, rc_file._data))) |
| 1187 | throw std::string("Cannot proceed without rc file."); |
| 1188 | |
| 1189 | Datetime now; |
| 1190 | std::stringstream contents; |
| 1191 | contents << "# [Created by " << PACKAGE_STRING << ' ' << now.toString("m/d/Y H:N:S") << "]\n" |
| 1192 | << "data.location=" << data_dir._original << "\n" |
| 1193 | << "news.version=" << Version::Current() << "\n" |
| 1194 | << "\n# To use the default location of the XDG directories,\n" |
| 1195 | << "# move this configuration file from ~/.taskrc to ~/.config/task/taskrc and update " |
| 1196 | "location config as follows:\n" |
| 1197 | << "\n#data.location=~/.local/share/task\n" |
| 1198 | << "#hooks.location=~/.config/task/hooks\n" |
| 1199 | << "\n# Color theme (uncomment one to use)\n" |
| 1200 | << "#include light-16.theme\n" |
| 1201 | << "#include light-256.theme\n" |
| 1202 | << "#include bubblegum-256.theme\n" |
| 1203 | << "#include dark-16.theme\n" |
| 1204 | << "#include dark-256.theme\n" |
| 1205 | << "#include dark-red-256.theme\n" |
| 1206 | << "#include dark-green-256.theme\n" |
| 1207 | << "#include dark-blue-256.theme\n" |
| 1208 | << "#include dark-violets-256.theme\n" |
| 1209 | << "#include dark-yellow-green.theme\n" |
| 1210 | << "#include dark-gray-256.theme\n" |
| 1211 | << "#include dark-gray-blue-256.theme\n" |
| 1212 | << "#include solarized-dark-256.theme\n" |
| 1213 | << "#include solarized-light-256.theme\n" |
| 1214 | << "#include no-color.theme\n" |
| 1215 | << '\n'; |
| 1216 | |
| 1217 | // Write out the new file. |
| 1218 | if (!File::write(rc_file._data, contents.str())) |
| 1219 | throw format("Could not write to '{1}'.", rc_file._data); |
| 1220 | |
| 1221 | // Load it so that it takes effect for this run. |
| 1222 | config.load(rc_file); |
| 1223 | } |
| 1224 | } |
| 1225 | |
| 1226 | //////////////////////////////////////////////////////////////////////////////// |
| 1227 | void Context::decomposeSortField(const std::string& field, std::string& key, bool& ascending, |