diff --git a/README.md b/README.md index ca8b8e1..d821183 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This is an [Obsidian](https://obsidian.md) plugin that allows viewing [taskwarri ## Task tables To include a table of tasks, use a `task-table` code block. The text inside the code block is parsed as YAML; include a key called `command` with the taskwarrior command that should be executed to generate the table. The syntax for this is exactly the same as the taskwarrior CLI syntax except that: -- The report name must immediately follow `task`. For example, `task list +nonsense` is legal, but `task +nonsense list` is not. +- The report name must be the last token, and will not be defaulted if not provided. For example, `task +nonsense list` is legal, but `task list +nonsense` and `task +nonsense` are not. - Some overrides are provided so the resulting ascii table can be parsed to an HTML table; `rc.detection` is set to `off`, and `rc.defaultWidth` is set to `1000`. A basic use-case might look like: diff --git a/main.ts b/main.ts index 601ba88..42a1ecb 100644 --- a/main.ts +++ b/main.ts @@ -1,13 +1,40 @@ -import { Plugin, Notice, MarkdownPostProcessor } from 'obsidian'; -import { exec, execSync } from 'child_process' -import { parse } from 'yaml' +import { Plugin, parseYaml, PluginSettingTab, Setting, App } from 'obsidian'; +import { execSync } from 'child_process' interface Settings { taskBinaryPath: string; } const DEFAULT_SETTINGS: Settings = { - taskBinaryPath: 'wsl task' + taskBinaryPath: 'task' +} + +export class EgoRockSettingsTab extends PluginSettingTab { + plugin: EgoRock + + constructor(app: App, plugin: EgoRock) { + super(app, plugin) + this.plugin = plugin + } + + display(): void { + let { containerEl } = this + + containerEl.empty() + + new Setting(containerEl) + .setName('Taskwarrior binary path') + .setDesc('The path to the taskwarrior binary. If task is on the system PATH, "task" should work. Otherwise, provide an absolute path. WSL systems can invoke taskwarrior running in WSL from windows with the path "wsl task".') + .addText((text) => + text + .setPlaceholder("task") + .setValue(this.plugin.settings.taskBinaryPath) + .onChange(async (value) => { + this.plugin.settings.taskBinaryPath = value + await this.plugin.saveSettings() + }) + ) + } } export default class EgoRock extends Plugin { @@ -15,6 +42,7 @@ export default class EgoRock extends Plugin { async onload() { await this.loadSettings(); + this.addSettingTab(new EgoRockSettingsTab(this.app, this)) this.registerMarkdownCodeBlockProcessor('task-table', (source, element, context) => { this.doCommandReturnString(parseYaml(source).command, element, this.settings.taskBinaryPath) @@ -87,9 +115,9 @@ export default class EgoRock extends Plugin { doCommandReturnString(commandString: string, el: any, taskwarriorBin='wsl task') { commandString = commandString.replace(/^task /, '') const reports = this.getReportNames() - const report = commandString.split(' ')[0] + const report = commandString.split(' ').slice(-1)[0] if (reports.includes(report)) { - const newCommand = `${taskwarriorBin.trim()} rc.detection:off rc.defaultwidth:1000 ${commandString.split(' ').slice(1).join(' ')} ${report}` + const newCommand = `${taskwarriorBin.trim()} rc.detection:off rc.defaultwidth:1000 ${commandString}` const asciiTable = execSync(newCommand).toString().split('\n') .filter((line) => { if (line.match(/^[ -]*$/)) return false