From b2f437b21a78458c8ea6ef35bef6a97107d1b83a Mon Sep 17 00:00:00 2001 From: Sinan Kanidagli Date: Thu, 4 Apr 2024 21:15:44 +0300 Subject: [PATCH] feat(tasko): new tasko plugin --- plugins/tasko/README.md | 11 ++++++++++ plugins/tasko/tasko.plugin.zsh | 38 ++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 plugins/tasko/README.md create mode 100644 plugins/tasko/tasko.plugin.zsh diff --git a/plugins/tasko/README.md b/plugins/tasko/README.md new file mode 100644 index 000000000..a553e3b64 --- /dev/null +++ b/plugins/tasko/README.md @@ -0,0 +1,11 @@ +# TaskWarrior Plugin + +Open annotation content with native open commands (xdg-open or open) + +To use it add `tasko` to the plugins array in your zshrc file: + +```zsh +plugins=(... tasko) +``` + +**Note:** you have to [install taskwarrior](https://github.com/GothenburgBitFactory/taskwarrior) first. diff --git a/plugins/tasko/tasko.plugin.zsh b/plugins/tasko/tasko.plugin.zsh new file mode 100644 index 000000000..3e11b7568 --- /dev/null +++ b/plugins/tasko/tasko.plugin.zsh @@ -0,0 +1,38 @@ +function _tasko_print_help() { + echo + echo "Usage: tasko {TASK} {ROW}" + echo +} + +function tasko () { + if [[ $# -ne 2 ]]; then + echo 'Error: Too many/few arguments, expecting two.' >&2 + tasko_print_help + return 1 + fi + + local annotation_desc=$(task _get $1.annotations.$2.description 2>/dev/null) + if [[ $? -ne 0 ]]; then + echo "Error: Task or row not found." >&2 + return 1 + fi + + if [[ $annotation_desc == "" ]]; then + echo "Error: No text found" >&2 + return 1 + fi + + echo "Open $annotation_desc? [y/n]" + read answer + if [[ $answer == y* ]] || [[ $answer == Y* ]]; then + if [[ $(uname -s) == "Linux" ]]; then + xdg-open $annotation_desc + return 0 + else + open $annotation_desc + return 0 + fi + return 1 + fi + return 0 +}