Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
976 B

  1. #!/bin/bash
  2. NOTES_FOLDER="$HOME/Documents/Notes"
  3. JSON_DB="$NOTES_FOLDER/books.yml"
  4. function exists_or_create() {
  5. if [[ -f "$2" ]]; then
  6. echo "Not Creating the note: File is already there"
  7. else
  8. echo -e "$1 \n$2"
  9. echo -e "# Book: $1\n" > "$2"
  10. cat <<EOF >> $JSON_DB
  11. - book: "$1"
  12. hash: "$(basename $2)"
  13. date: "$(date '+%d/%m/%Y %H:%M:%S')"
  14. EOF
  15. fi
  16. }
  17. function add_annotation() {
  18. selection=$(xclip -out -selection clipboard | sed ':a;N;$!ba;s/\n/ /g')
  19. text=""
  20. ccount=0
  21. for word in $selection; do
  22. ccount=$(( $ccount + $(echo $word | wc -c)))
  23. if [ $ccount -gt 75 ]; then
  24. ccount=0
  25. echo "$(echo $text | xargs)" >> $1
  26. text=""
  27. fi
  28. text="$text$word "
  29. done
  30. echo -e "> <!!>\n" >> $1
  31. }
  32. hashed_filename="$NOTES_FOLDER/$(md5sum "$1" | cut -f1 -d' ').md"
  33. filename=$(basename "$@")
  34. exists_or_create "$filename" "$hashed_filename"
  35. add_annotation "$hashed_filename"