dotfiles/bin/notes

78 lines
1.8 KiB
Text
Raw Normal View History

2011-04-03 10:24:57 +00:00
#!/bin/bash
#
#
# actions available:
#
# new -> create a new note for Today
# edit -> edit the note of Today
2011-04-18 20:00:23 +00:00
# todo -> list todos []
2011-04-03 10:24:57 +00:00
#
# Ugly notes script made by Alexandre Dulaunoy
# and released under the GNU General Public License
#
#
NOTESPATH="${HOME}/.notes"
if ! [ -e "${NOTESPATH}" ]
then
mkdir ${NOTESPATH}
2011-04-03 12:29:53 +00:00
fi
2011-04-03 10:24:57 +00:00
if ! [ -d "${NOTESPATH}/.git" ]
then
cd ${NOTESPATH}
git init
fi
function GetPath {
2011-04-03 12:29:53 +00:00
echo ${NOTESPATH}/$( date +%Y )/$( date +%m )
2011-04-03 10:24:57 +00:00
}
TODAYPATH=$(GetPath)
function WhereIAm {
echo `curl -s -m 2 http://api.hostip.info/ | egrep "(countryName)|(gml:name)" | grep -v "hostip" | sed -e :a -e 's/<[^>]*>//g;/</N;//ba' | sed -e "s/\\n//g" | fmt`
}
function Template {
TMPFILE="tmp-"$$
echo ">> " ${WHAT} `date` "@" $( WhereIAm ) >>${NOTESPATH}/${TMPFILE}
echo "with:" `id -nu`",ADD" >>${NOTESPATH}/${TMPFILE}
echo "<<end" >>${NOTESPATH}/${TMPFILE}
if ! [ -e "$TODAYPATH" ]
then
mkdir -p ${TODAYPATH}
2011-04-03 12:29:53 +00:00
fi
2011-04-03 10:24:57 +00:00
cat ${NOTESPATH}/${TMPFILE} >>${TODAYPATH}/$( date +%d)
rm ${NOTESPATH}/${TMPFILE}
}
ACTION=$1
WHAT=$2
if [ "${ACTION}" == "new" ]
then
Template
vim ${TODAYPATH}/$( date +%d)
2011-04-03 12:29:53 +00:00
cd ${TODAYPATH}
2011-04-03 10:24:57 +00:00
git add ${TODAYPATH}/$( date +%d)
git commit -m "${WHAT} saved" ${TODAYPATH}/$( date +%d)
elif [ "${ACTION}" == "edit" ]
then
vim ${TODAYPATH}/$( date +%d)
2011-04-18 19:32:43 +00:00
elif [ "${ACTION}" == "todo" ]
then
cd ${NOTESPATH}
find . -type f | grep -v "/\." | xargs -d"\n" grep "\[\]"
2011-04-18 20:00:23 +00:00
elif [ "${ACTION}" == "list" ]
then
cd ${NOTESPATH}
find . -type f | grep -v "/\." | xargs -d"\n" wc -m | grep -v "total"
2011-04-03 10:24:57 +00:00
else
echo "unknown action"
2011-04-18 20:00:23 +00:00
echo "available action : [new|edit|todo]"
2011-04-03 10:24:57 +00:00
exit 1
fi