#!/bin/bash action=$1 shift [ "$action" = "usage" ] && { echo " Add new item with same contexts and" echo " projects as the previous item:" echo " addr [ITEM]" echo "" exit } if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then read -p "Add: " -e -r input else input=$* fi # get the last line added and its content lastitem=$(sed -n '$ =' "$TODO_FILE") getNewtodo "$lastitem" contexts="$(listWordsWithSigil '@' "$newtodo")" projects="$(listWordsWithSigil '+' "$newtodo")" # remove duplicates to_append="$(echo "$projects $contexts" | sed 's/^[ \t]*//;s/[ \t]*$//')" if [ -n "$to_append" ]; then input="$input $to_append" fi "$TODO_SH" command add "$input"