Skip to content

Instantly share code, notes, and snippets.

@remyrd
Created November 14, 2022 22:12
Show Gist options
  • Save remyrd/c5485cd3a30e968fcf22f8fff8f69f36 to your computer and use it in GitHub Desktop.
Save remyrd/c5485cd3a30e968fcf22f8fff8f69f36 to your computer and use it in GitHub Desktop.
TODO script
##### TODO list -- add this to your ~/.{bash|zsh|fish}rc or source it
# Your TODOs in your terminal.
# Incomplete TODOs carry over to the next day.
# A TUI (default fzf) helps with completion
# USAGE
# $ todo break this by typing a non alphanumeric such as single quote
# $ complete-todo
# $ check-today-todos
# SET THESE TO YOUR BEST CONVENIENCE
TODOPATH=$HOME/todo # Storage dir. One file per todo, make sure the path is available
TODO_COMPLETE_CMD=fzf # Some TUI to complete todos. Alternatives include dmenu, rofi, etc
YDAY="$(date -I --date='yesterday')" # Linux only (probably)... sorry! (not sorry)
TODAY="$(date -I)" # Today in YYYY-MM-DD format
function colorize(){
sed 's/TODO/\\033\[30;41mTODO\\033\[0m/' | sed 's/DONE/\\033\[30;42mDONE\\033\[0m/'
}
function copy-previous-day-todos() {
local notfoundmsg="Couldn't copy any entries from $TODOPATH/$YDAY*.txt
If you don't have any entries you can disregard this message.
If you haven't opened the terminal in some time, try running
YDAY=<YYYY-MM-DD> copy-previous-day-todos"
local found="$(/usr/bin/cat $TODOPATH/$YDAY*.txt 2> /dev/null)"
if [ "$found" = "" ]
then
echo "$notfoundmsg"
else
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)"
}
check-today-todos
@remyrd
Copy link
Author

remyrd commented Nov 15, 2022

Excellent! Would be fun to create something in a proper programming language. May be a Go application. Bash is an eye sore smile

@neilpanchal thanks, I really enjoy the hacky-ness of it all - the first iteration was a functional within 10min and it only relied on 5 GNU commands. I do agree as time went by I traded some eye-care for better UX though :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment