note.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. ## This was taken from http://netninja.com/2011/05/03/trunk-notes-lookups-from-the-desktop/
  3. # slight mod made for my path
  4. # I use this for my old Notational Velocity data.
  5. # still need a good linux way to do nvAlt
  6. if [ -z "$1" ]; then
  7. echo "Put search term on command line"
  8. exit 1
  9. fi
  10. # Set this to:
  11. # 0 to only show matching notes
  12. # 1 to show matches lines in context first, before printing matching notes
  13. PRINT_MATCHES_IN_CONTEXT=0
  14. # Find matches
  15. LIST=/tmp/notelist.$$.txt
  16. grep -r -i -l "$1" ~/Notes > $LIST
  17. if [ $PRINT_MATCHES_IN_CONTEXT -eq 1 ]; then
  18. grep -r -i --color "$1" ~/Notes
  19. echo ""
  20. fi
  21. # Display list of matching files
  22. exec<$LIST
  23. COUNTER=1
  24. echo "[0] abort"
  25. while read LINE
  26. do
  27. FILE=`basename "$LINE"`
  28. echo "[$COUNTER] $FILE"
  29. ((COUNTER=COUNTER + 1))
  30. done
  31. # Ask for selection
  32. exec<&1
  33. echo -n "Selection: "
  34. read SELECTION
  35. # Find file that matches selection and display it
  36. exec<$LIST
  37. COUNTER=1
  38. while read LINE
  39. do
  40. if [ "$COUNTER" == "$SELECTION" ]; then
  41. less -i -p "$1" "$LINE"
  42. fi
  43. ((COUNTER=COUNTER + 1))
  44. done
  45. # Clean up temp file
  46. rm -f $LIST