Skip to content

Instantly share code, notes, and snippets.

@apcomplete
Created April 4, 2012 18:40
Show Gist options
  • Save apcomplete/2304608 to your computer and use it in GitHub Desktop.
Save apcomplete/2304608 to your computer and use it in GitHub Desktop.
todo.txt notes action
#!/bin/bash
TODOTXT_VERBOSE=0
DEFAULT_NOTES_ACTION="listnotes"
listnotes() {
TODO_LIST_NOTES="ls $TODO_NOTES_DIR | xargs -0 basename | sed -e 's/\.[a-z]\{3\}$//'"
if [ ! -z $TODO_NOTES_PROJECT ]
then
TODO_LIST_NOTES+=" | grep -i $TODO_NOTES_PROJECT"
fi
eval $TODO_LIST_NOTES
}
open_notes(){
FILE=$TODO_NOTES_DIR/${TODO_NOTES_PROJECT}.txt
if [ ! -f $FILE ]
then
read -p "There are no project notes for project $TODO_NOTES_PROJECT. Do you wish to create them? [y/n]: " yn
case $yn in
[Yy]* ) ;;
[Nn]* ) echo "No action will be taken."; exit;;
* ) echo "Please provide a valid answer.";;
esac
fi
$EDITOR $FILE
}
case $1 in
"usage")
echo "$(basename $0) [BASENAME]"
echo " Open \$TODO_NOTES_DIR/BASENAME.txt in \$EDITOR."
echo " If BASENAME is not given, defaults to 'todo'."
;;
"notes")
case "$2" in
"")
eval $DEFAULT_NOTES_ACTION;;
"-l"|"list")
if [ -z $3 ]
then
listnotes
else
TODO_NOTES_PROJECT=$3
listnotes
fi
;;
"-d"|"remove")
rm -v $TODO_NOTES_DIR/$3.txt
;;
*)
TODO_NOTES_PROJECT=$2
open_notes
;;
esac
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment