Skip to content

Instantly share code, notes, and snippets.

@remyrd
Created November 14, 2022 22:12
Show Gist options
  • Select an option

  • Save remyrd/c5485cd3a30e968fcf22f8fff8f69f36 to your computer and use it in GitHub Desktop.

Select an option

Save remyrd/c5485cd3a30e968fcf22f8fff8f69f36 to your computer and use it in GitHub Desktop.

Revisions

  1. remyrd created this gist Nov 14, 2022.
    64 changes: 64 additions & 0 deletions todol.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    ##### 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