I am a big fan of to-do lists: having a to-do list always at hand relaxes me :-).

image

But I’m also a big fan of command line interfaces: so on all my Linux boxes I started using a simple modification of the .bashrc configuration file to help me enter and display tasks.

Here are the lines to add to the end of .bashrc:

#-----------------------------------------------------------------------
# Bashtask
#
#    Usage
#	tasklist 
#	taskadd: taskadd 'Fix the bug'
#    	taskin:  taskin 'Insert a task on line 4' 4
#    	taskrm:  taskrm 4 #Removes item 4 on the list
#    	taskcl:  taskcl #Removes all tasks 
#
TASKFILE="$HOME/.bashtask" 
NC='\033[0m' 
LIGHTRED='\e[1;31m'
LIGHTBLUE='\e[1;34m'

function tasklist() {
if [ -f "$TASKFILE" ] && [ $(stat -c %s "$TASKFILE") != 0 ] #Check if file has content
then
    echo -e "${LIGHTRED}Task List${NC} as of ${LIGHTBLUE}$(date -r "$TASKFILE")${NC}"
    echo ""
    cat "$TASKFILE"
    printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' "-"
else
    echo "Good, no tasks! :)"
    printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' "-"
    touch "$TASKFILE"
fi
}
function taskadd() { echo "- $1" >> "$TASKFILE"; }
function taskin() { sed -i "$1i- $2" "$TASKFILE"; }
function taskrm() { sed -i "$1d" "$TASKFILE"; }
function taskcl() { rm "$TASKFILE"; touch "$TASKFILE"; }

tasklist
#-----------------------------------------------------------------------

I hope it is useful!