40 lines bash script for TODO list

1 min read Original article ↗
#!/bin/bash
if [ ! -d "$HOME/.td" ]
then
mkdir "$HOME/.td"
fi
if [ $1 = 'a' ]
then
to_add=${@: 2}
echo "Added: \"$to_add\""
if [ -s ~/.td/todo.txt ]
then
echo "$to_add" >> ~/.td/todo.txt
else
echo "$to_add" > ~/.td/todo.txt
fi
fi
if [ $1 = 'l' ]
then
cat ~/.td/todo.txt 2> /dev/null
fi
if [ $1 = 'p' ]
then
finished=$(head -1 ~/.td/todo.txt)
todo=$(tail -n +2 ~/.td/todo.txt)
if [ -z "$todo" ]
then
echo -n "" > ~/.td/todo.txt
else
echo "$todo" > ~/.td/todo.txt
fi
echo "Done: \"$finished\""
fi
if [ $1 = 'c' ]
then
head -1 ~/.td/todo.txt
fi