Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 54 lines (47 sloc) 1.25 KB
#! /usr/bin/env bash
# vim:filetype=sh
if [[ "x$TODO" = x ]]; then
BADOOP=~/.todo.txt
else
BADOOP="$TODO"
fi
function badoop_usage() {
echo "badoop"
echo " -h: Print this help"
echo " -d: delete any todo items matching remaining arguments"
echo " with no flags: add the string passed in to the todo list"
echo " with no arguments: print out todo list"
}
# Badoop-done. Delete from todo list
function badone() {
# $@ is all the arguments passed in.
# not sure what d is. Flag to delete anything that matches?
if [[ -f "$BADOOP" ]]; then
if [[ $@ = "" ]]; then
echo "Error: Please provide a keyword matching a word in the TODO item to be deleted or the number of the TODO item to be deleted"
elif [[ $@ = *[^0-9]* ]]; then
sed -i -e "/$@/d" "$BADOOP";
else
sed -i $@'d' "$BADOOP";
fi
fi
}
function badoop() {
# $# is the number of parameters passed in
# command with no args just shows all todos
if [[ $# == "0" ]]; then
if [[ -f "$BADOOP" ]]; then
cat -n "$BADOOP";
fi
elif [[ $1 == "-h" ]]; then
badoop_usage
elif [[ $1 == "-d" ]]; then
shift
badone $@
else
# adding a new todo
# $@ is a string containing all parameters
echo "$@" >> "$BADOOP"
fi
}
badoop $@