Skip to content

Instantly share code, notes, and snippets.

Created January 14, 2012 13:21
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1611400 to your computer and use it in GitHub Desktop.
Save anonymous/1611400 to your computer and use it in GitHub Desktop.
Minimally Awesome Todos for Mac OS X
# Reference: http://blog.jerodsanto.net/2010/12/minimally-awesome-todos/
#
# Improvements:
#
# *) It now supports tracking multiple projects/todo files.
# *) Use 'cat -b' to get task order instead of hard-coding line number in files.
#
# 3 actions available:
# - Create a new task in project "prj": td prj task
# - Delete third task: tddone prj 3
# - Move third task on the top: tdtop pro 3
#
export TODO_DIR="${HOME}/.todo"
export TODO_DEFAULT_PROJECT='irm'
_todo_check_project_file() {
# Usage: _todo_check_project_file project_name
project_name="${1}"
project_file="${TODO_DIR}/${project_name}"
# Create project file if not exist.
[ -d ${TODO_DIR} ] || mkdir -p ${TODO_DIR} &>/dev/null
[ -f ${project_file} ] || touch ${project_file} &>/dev/null
}
_todo_add() {
# Usage: _todo_add project_name task
project_name="${1}"
project_file="${TODO_DIR}/${project_name}"
_todo_check_project_file ${project_name}
# Remove project_name from position parameter list.
shift 1
if [ X"$#" != X"0" ]; then
cat -b ${project_file}
else
echo "$@" >> ${project_file}
fi
}
td() {
# List existing tasks or add a new task.
# Usage:
# - List existing tasks in project 'prj': td prj
# - Add a new task in project 'pro': td prj task
# Get project name
if [ X"$#" == X'0' ]; then
project_name="${TODO_DEFAULT_PROJECT}"
else
project_name="${1}"
fi
project_file="${TODO_DIR}/${project_name}"
_todo_check_project_file ${project_name}
if [ X"$#" == X"0" -o X"$#" == X"1" ]; then
cat -b ${project_file}
else
shift 1
echo "$@" >> ${project_file}
fi
}
tddone() {
# Delete task.
# Usage:
# - Delete third task in project 'prj': tddone prj 3
# Get project name
if [ X"$#" != X'2' ]; then
exit 255
fi
project_name="${1}"
project_file="${TODO_DIR}/${project_name}"
_todo_check_project_file ${project_name}
export line="${2}"
sed "${line}d" ${project_file} > ${project_file}.tmp
mv ${project_file}.tmp ${project_file}
}
tdtop() {
# Move task to the top
# Usage:
# - Move third task in project 'prj' to the top: tdtop prj 3
# Get project name
if [ X"$#" == X'2' ]; then
project_name="${1}"
project_file="${TODO_DIR}/${project_name}"
_todo_check_project_file ${project_name}
sed -n "${2}p" ${project_file} > ${project_file}.top
tddone ${project_name} ${2}
cat ${project_file} >> ${project_file}.top
mv ${project_file}.top ${project_file}
else
:
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment