From 1e7adfa51ca096af8b21638854d7195611488340 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Tue, 29 Apr 2025 18:41:24 +0100 Subject: [PATCH] Create inbox todo.txt addon --- .todo.actions.d/inbox | 79 +++++++++++++++++++++++++++++++++++++++++++ .zshrc | 1 - 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100755 .todo.actions.d/inbox diff --git a/.todo.actions.d/inbox b/.todo.actions.d/inbox new file mode 100755 index 0000000..0e62fe6 --- /dev/null +++ b/.todo.actions.d/inbox @@ -0,0 +1,79 @@ +#!/bin/bash + +## Inbox todos storage file ## +export INBOX_PATH="$TODO_DIR" +export INBOX_FILE="inbox.txt" +export INBOX_FULL_PATH="$INBOX_PATH/$INBOX_FILE" +#export INBOX_THRESHOLD="14d" + +## Display usage information ## +function usage { + cat <<-END + + inbox - Create and manage your inbox tasks + + Usage: + inbox ls + List todos in $INBOX_FILE + + inbox move ITEM# + Move specified todo out of $INBOX_FILE + + inbox add DESCRIPTION + Add new todo to $INBOX_FILE + + END + + exit 0 +} + +## Lists todos in stale.txt ## +function listInboxTodos { + $TODO_FULL_SH listfile "$INBOX_FULL_PATH" + + exit 0 +} + +## Moves todo from inbox.txt to todo.txt ## +function moveTodo { + itemnum="$1" + getTodo "$itemnum" "$INBOX_FULL_PATH" + cleanTodo=$(echo "$todo" | sed -E 's/x [0-9]{4}-[0-9]{2}-[0-9]{2} //') + $TODO_FULL_SH add "$cleanTodo" + if [ $TODOTXT_PRESERVE_LINE_NUMBERS = 0 ]; then + # delete line (changes line numbers) + sed -i.bak -e "${itemnum}s/^.*//" -e '/./!d' "$INBOX_FULL_PATH" + else + # leave blank line behind (preserves line numbers) + sed -i.bak -e "${itemnum}s/^.*//" "$INBOX_FULL_PATH" +fi + exit 0 +} + +## Add todo to inbox.txt ## +function addTodo { + description="$1" + $TODO_FULL_SH addto inbox.txt "$description" +} + + +action=$1 +shift + +if [ "$1" = "usage" ]; then + usage +fi + +if [ "$1" = "ls" ]; then + listInboxTodos +elif [ "$1" = "move" ] && [[ "$2" =~ [0-9]+ ]]; then + moveTodo "$2" +elif [ "$1" = "add" ] && [[ -n "$2" ]]; then + addTodo "$2" +else + cat <<-EndShortUsage + $TODO_SH inbox ls | List inbox tasks + $TODO_SH inbox move ITEM# | Move item from $INBOX_FILE to todo.txt + $TODO_SH inbox add DESCRIPTION | Add todo to $INBOX_FILE + EndShortUsage +fi diff --git a/.zshrc b/.zshrc index fa10a8c..59d0ae9 100644 --- a/.zshrc +++ b/.zshrc @@ -20,7 +20,6 @@ SAVEHIST=10000 alias lss="ls -lah" alias yt-dlp-mp4="yt-dlp --no-config --format 'bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4]'" alias t="todo.sh" -alias ti="todo.sh addto inbox.txt" alias gco="git checkout" alias gcm="git commit -m"