Created
August 11, 2023 13:32
-
-
Save remyrd/bb9d4e2a8c7ab7b1d1c1e7524adc6aac to your computer and use it in GitHub Desktop.
todo.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### TODO list | |
TODOPATH=$HOME/todo | |
TODO_COMPLETE_CMD=fzf | |
TODAY="$(date -I)" | |
function colorize(){ | |
sed 's/TODO/\\033\[30;41mTODO\\033\[0m/' | sed 's/DONE/\\033\[30;42mDONE\\033\[0m/' | |
} | |
function copy-previous-day-todos() { | |
local prev_day="$(/usr/bin/ls $TODOPATH | tail -1 | awk -F'T' '{print $1}')" | |
local found="$(/usr/bin/cat $TODOPATH/$prev_day*.txt 2> /dev/null)" | |
echo "$found" | grep "TODO" | while read t | |
do | |
sleep 0.01 | |
echo "$t" > $TODOPATH/$(date -Ins).txt | |
done | |
fi | |
} | |
function get-today-todos() { | |
/usr/bin/cat $TODOPATH/$TODAY*.txt | grep ".+" | |
} | |
function check-today-todos() { | |
if [ "$(get-today-todos 2> /dev/null)" = "" ] | |
then | |
copy-previous-day-todos | |
fi | |
echo "$(get-today-todos | colorize)" | |
} | |
function todo() { | |
echo "TODO $@" >> $TODOPATH/$(date -Iseconds).txt | |
check-today-todos | |
} | |
function complete-todo() { | |
local toreplacetext="$(get-today-todos | grep TODO | sed 's/TODO //' | $TODO_COMPLETE_CMD)" | |
local toreplacefile=$(grep "TODO $toreplacetext" $TODOPATH/$TODAY*.txt -l | head -1) | |
sed -i 's/TODO/DONE/' $toreplacefile | |
echo "$(get-today-todos | colorize)" | |
} | |
echo "add a todo: todo foo bar baz" | |
echo "complete a todo (interactive): complete-todo" | |
check-today-todos |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment