From 4fe83e65e0c5620e114a49152351c7719606ab14 Mon Sep 17 00:00:00 2001 From: Oleksandr Smirnov Date: Sun, 22 Jun 2025 18:48:00 +0300 Subject: [PATCH] todo: add action for opening urls in todos --- config/todo/actions/@ | 10 ++++++++++ config/todo/actions/url | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100755 config/todo/actions/url diff --git a/config/todo/actions/@ b/config/todo/actions/@ index 9aa2336..79f767e 100755 --- a/config/todo/actions/@ +++ b/config/todo/actions/@ @@ -1,7 +1,17 @@ #!/usr/bin/env bash +export TODOTXT_VERBOSE=0 + action=$1 shift +if [[ $action == "usage" ]]; then + echo "@ [context]" + echo " Lists all tasks with the given context." + echo " If no context is given, lists all tasks categorized by their context." + echo " If task has @someday, it won't be listed." + exit 0 +fi + CONTEXTS=$(grep -o '[^ ]*@[^ ]\+' "$TODO_FILE" | grep '^@' | sort -u | sed 's/^@//g' ) for context in $CONTEXTS ; do if [[ $context == "someday" ]]; then diff --git a/config/todo/actions/url b/config/todo/actions/url new file mode 100755 index 0000000..707a627 --- /dev/null +++ b/config/todo/actions/url @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +action=$1 +shift + +if [[ $action == "usage" ]]; then + echo "url [task_number] - opens link in the task" + exit 0 +fi + +item=$1 +if [[ ! "$item" =~ ^[0-9]+$ ]]; then + echo "$item: invalid item number" + exit 1 +fi + +URL_REGEX="\b(?:https?:\/\/)?(?:[\w-]+\.)+[a-z]{2,}(?:\/[\w\-./?%&=:#@+]*)?" +URL=$(sed "$item!d" "$TODO_FILE" | grep -Po "$URL_REGEX") + +if [[ -z "$URL" ]]; then + echo "No URL found in task $item" + exit 1 +fi + +if [[ ! "#URL" =~ ^(?!https?:\/\/) ]]; then + URL="https://$URL" +fi + +echo "$URL" +xdg-open "$URL" &>/dev/null