1
0
Fork 0
mirror of https://github.com/marty-oehme/scripts.git synced 2024-12-22 07:58:08 +00:00

Merge pull request #7 from fmakowski/master

Taskwarrior 0.0.5: Added possibility to specify tags
This commit is contained in:
Patrizio Bekerle 2017-06-19 15:33:39 +02:00 committed by GitHub
commit 5e6fb4c709
3 changed files with 72 additions and 11 deletions

View file

@ -17,6 +17,7 @@ To export a set of tasks, you need to select text, and then click `Export to Tas
* project names should be formatted as headers, and may be nested * project names should be formatted as headers, and may be nested
* the tasks are taken only from the unordered list items - lines that are starting with asterisk (*) or minus sign (-) * the tasks are taken only from the unordered list items - lines that are starting with asterisk (*) or minus sign (-)
* tags for the tasks may be added by specifying `+taskname` at the end of the note. You may do that multiple times.
* any other content will be skipped - any additional comments or empty lines do not matter during the parsing process. * any other content will be skipped - any additional comments or empty lines do not matter during the parsing process.
### Example ### Example
@ -26,20 +27,20 @@ The following Markdown text:
## Project1 ## Project1
* task one * task one
### Subproject1 ### Subproject1
* task two * task two +test
Some additional portion of text, describing how awesome project 1 is Some additional portion of text, describing how awesome project 1 is
* task three * task three
### Subproject2 ### Subproject2
* task four * task four +tagged +few +times
# Project2 # Project2
* task five * task five
should generate following calls to Taskwarrior: should generate following calls to Taskwarrior:
task add pro:Project1 task one task add pro:Project1 task one
task add pro:Project1.Subproject1 task two task add pro:Project1.Subproject1 task two tags:"test"
task add pro:Project1.Subroject1 task three task add pro:Project1.Subroject1 task three
task add pro:Project1.Subproject2 task four task add pro:Project1.Subproject2 task four tags:"tagged few times"
task add pro:Project2 task five task add pro:Project2 task five
## Import (TW -> note) ## Import (TW -> note)
@ -71,10 +72,10 @@ will be replaced by:
# Project1 # Project1
* task one * task one
## Subproject2 ## Subproject2
* task four * task four +tagged +few +times
* task four * task four
## Subproject1 ## Subproject1
* task two * task two +test
Something written here. Something written here.
# Project3 # Project3
# Project2 # Project2

View file

@ -2,7 +2,7 @@
"name": "Taskwarrior", "name": "Taskwarrior",
"identifier": "taskwarrior", "identifier": "taskwarrior",
"script": "taskwarrior.qml", "script": "taskwarrior.qml",
"version": "0.0.4", "version": "0.0.5",
"minAppVersion": "17.06.4", "minAppVersion": "17.06.4",
"authors": ["@fmakowski"], "authors": ["@fmakowski"],
"platforms": ["linux", "macos"], "platforms": ["linux", "macos"],

View file

@ -149,10 +149,27 @@ QtObject {
var isTask = taskRegExp.exec(line); var isTask = taskRegExp.exec(line);
if (isTask) { if (isTask) {
var tags = [];
taskDescription = isTask[1]; taskDescription = isTask[1];
logIfVerbose("Detected task: " + taskDescription); logIfVerbose("Detected task: " + taskDescription);
var fetchTag;
var tagExp = /^(.+)?[\s*]?\+(.+)$/;
var currentTaskDescription = taskDescription;
do {
logIfVerbose("Fetching tags...");
fetchTag = tagExp.exec(currentTaskDescription);
if (fetchTag) {
logIfVerbose("Tag " + fetchTag[2] + " found!");
tags.push(fetchTag[2]);
currentTaskDescription = fetchTag[1];
var re = new RegExp("\\+" + fetchTag[2].replace(/ /g, ''), "i");
taskDescription = taskDescription.replace(re,'');
} else
break;
} while(currentTaskDescription);
var concatenatedProjectName = projectName.join('.'); var concatenatedProjectName = projectName.join('.');
if (tags.length == 0) {
logIfVerbose("Executing \"" + taskPath + " add pro:" + concatenatedProjectName + " " + taskDescription + "\""); logIfVerbose("Executing \"" + taskPath + " add pro:" + concatenatedProjectName + " " + taskDescription + "\"");
script.startDetachedProcess(taskPath, script.startDetachedProcess(taskPath,
[ [
@ -160,6 +177,16 @@ QtObject {
"pro:" + concatenatedProjectName, "pro:" + concatenatedProjectName,
taskDescription taskDescription
]); ]);
} else {
logIfVerbose("Executing \"" + taskPath + " add pro:" + concatenatedProjectName + " " + taskDescription + " tags:\"" + tags.join(' ') + "\"\"");
script.startDetachedProcess(taskPath,
[
"add",
"pro:" + concatenatedProjectName,
taskDescription,
"tags:\"" + tags.join(' ') + "\""
]);
}
// We expect, that the task description would be the only thing in the line, hence `return`. // We expect, that the task description would be the only thing in the line, hence `return`.
return; return;
} }
@ -257,7 +284,42 @@ QtObject {
var taskParamsRegexp = /(\d+)[\s*]?(.+)?[\s*]?/i; var taskParamsRegexp = /(\d+)[\s*]?(.+)?[\s*]?/i;
var fetchTaskParams = taskParamsRegexp.exec(task); var fetchTaskParams = taskParamsRegexp.exec(task);
logIfVerbose("Extracted data from task: ID " + fetchTaskParams[1] + " Desc: " + fetchTaskParams[2]); logIfVerbose("Extracted data from task: ID " + fetchTaskParams[1] + " Desc: " + fetchTaskParams[2]);
var taskEntry = "* " + fetchTaskParams[2];
// We are fetching tags to append them to description line
var tagResult = script.startSynchronousProcess(taskPath,
[
fetchTaskParams[1],
"tag"
],
"");
var tagsPlainText = "";
if (tagResult) {
var tagsSeparated;
// The result does not contain any \n, so we are splitting by whitespace.
tagsSeparated = tagResult.toString().split('\n');
tagsSeparated.splice(0, 1); // removing ""
if (tagsSeparated.length === 0) {
logIfVerbose("No tags");
} else {
tagsSeparated.splice(0, 1); // removing headline
tagsSeparated.splice(0, 1); // removing "----"
tagsSeparated.splice(tagsSeparated.length - 1, 1); // removing ""
tagsSeparated.splice(tagsSeparated.length - 1, 1); // removing ""
tagsSeparated.splice(tagsSeparated.length - 1, 1); // removing ""
tagsSeparated.forEach( function(tag){
var tagsRegexp = /[\s*]?(.+)[\s*]?1[\s*]?/i;
var fetchTag = tagsRegexp.exec(tag);
tagsPlainText += " +" + fetchTag[1].replace(/ /g,'');
});
}
}
var taskEntry = "* " + fetchTaskParams[2] + tagsPlainText;
logIfVerbose("Inserting \"" + taskEntry + "\" after line " + projectNameLines[currentProjectNumber - 1]); logIfVerbose("Inserting \"" + taskEntry + "\" after line " + projectNameLines[currentProjectNumber - 1]);
plainText.splice(projectNameLines[currentProjectNumber - 1], 0, taskEntry); plainText.splice(projectNameLines[currentProjectNumber - 1], 0, taskEntry);
@ -278,9 +340,7 @@ QtObject {
"delete" "delete"
]); ]);
} }
} }
}); });
// Finally, selected text is replaced by the text with insertions. // Finally, selected text is replaced by the text with insertions.