#!/bin/sh # Note-taking Script: # http://jon.smajda.com/blog/2008/06/03/script-for-notes/ # # NOTES: # the only non-standard command is "trash" (6 lines up from bottom) # substitute rm or, on Macs, "sudo gem install osx-trash" to get trash set -e # some variables noteDir="/home/you/path/to/notes" notePrefix="note" # so note1, note2, etc. noteExtension="tex" # .tex, .txt, .whatever ####################################################### # Search through existing entries #### function for -s and -t options catFlagFunction () { findPattern=`echo $findPatterns | sed 's/ /|/g'` hline=`perl -e 'print "%" x60'` for i in $noteDir/*; do if [ ! -z $tagsOnly ]; then ### for -t flag, search only tags ### there's probably a better way but... if [ `grep TAGS $i | grep -Eic "$findPattern"` -ne 0 ]; then echo $hline cat $i fi else ### for -s flag, search all of the file if [ `grep -Eic "$findPattern" $i` -ne 0 ]; then echo $hline cat $i fi fi done } #### check if -s or -t is used while [ "${1:0:1}" = "-" ]; do case "$1" in '-s') catFlag='true' ;; '-t') catFlag='true' tagsOnly='true' ;; esac shift done #### save the rest as patterns to search findPatterns="$@" #### if -s or -t is used, send to catflagfunction if [ ! -z $catFlag ]; then catFlagFunction exit fi ####################################################### # Create new entry #### Get unique noteId counter=1 noteId=$notePrefix''$counter while [ -f $noteDir/"$noteId"."$noteExtension" ]; do counter=$((counter + 1)) noteId=$notePrefix''$counter done noteFile="$noteDir"/"$noteId"."$noteExtension" #### create template echo "% $counter" > "$noteFile" echo "% "`date` >> "$noteFile" echo "% TAGS: " >> "$noteFile" editPre=`cat "$noteFile"` # for checking after editing #### edit in vim (+3 puts you on line 3, use -c to set tex as filetype) #### or substitute your editor of choice: vi +3 -c ":set filetype=tex" "$noteFile" editPost=`cat "$noteFile"` # to check for edits #### check for edits then save if [ "$editPre" = "$editPost" ]; then echo "Cancelling $noteId.$noteExtension..." trash "$noteFile" echo "Done." else echo "Saving $noteId.$noteExtension..." echo "Done." fi