Code for drawings.hcoder.org
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.

38 lines
1.3KB

  1. #!/bin/bash
  2. # "Import" (MOVE) a picture from the given path to the given name.
  3. # For example, "import_pic.sh ~/Downloads/foo.jpg blah" will MOVE the
  4. # file ~/Downloads/foo.jpg to source/content/XX-blah.jpg, where XX is
  5. # the next unused number.
  6. DESTDIR=source/content
  7. if [ "$#" -ne 2 ]; then
  8. echo "ERROR: Need exactly two arguments" 1>&2
  9. echo "USAGE: import_pic.sh <path/to/file.jpg> <name>" 1>&2
  10. echo "EXAMPLE: import_pic.sh ~/Documents/foo.jpg study_hands" 1>&2
  11. exit 1
  12. fi
  13. FILE=$1
  14. NAME=`echo $2 | sed 's/-/_/g'`
  15. if [ ! -r "$FILE" ]; then
  16. echo "ERROR: Can't read '$FILE'" 1>&2
  17. echo "USAGE: import_pic.sh <path/to/file.jpg> <name>" 1>&2
  18. echo "EXAMPLE: import_pic.sh ~/Documents/foo.jpg study_hands" 1>&2
  19. exit 1
  20. fi
  21. LAST_NUMBER=`ls $DESTDIR/*.yaml | sed -e 's|.*/||' -e 's/-.*//' | tail -n 1`
  22. NEXT_NUMBER=`expr $LAST_NUMBER + 1`
  23. PADDED_NEXT_NUMBER=`printf "%03i" $NEXT_NUMBER`
  24. FILE_EXT=$(echo `basename "$FILE"` | sed 's/[^.]*//')
  25. mv "$FILE" $DESTDIR/$PADDED_NEXT_NUMBER-$NAME$FILE_EXT
  26. echo -e "---\ndescription: Description here\ndate: `date -R`\ntags:\n - scan\n - mdscan" >$DESTDIR/$PADDED_NEXT_NUMBER-$NAME.yaml
  27. echo "Imported as $PADDED_NEXT_NUMBER-$NAME.yaml / $PADDED_NEXT_NUMBER-$NAME$FILE_EXT"
  28. echo "Edit description with eg. 'emacs $DESTDIR/$PADDED_NEXT_NUMBER-$NAME.yaml'"