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.

new.sh 752B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env bash
  2. if [ "$1" == "" ]; then
  3. echo "Usage: new.sh 'Title of the Post'"
  4. exit 1
  5. fi
  6. cwd="$( cd "${BASH_SOURCE[0]%/*}" && pwd )"
  7. # Taken from https://gist.github.com/saml/4674977
  8. title="$1"
  9. max_length="${2:-48}"
  10. slug="$({
  11. tr '[:upper:]' '[:lower:]' | tr -cs '[:alnum:]' '-'
  12. } <<< "$title")"
  13. slug="${slug##-}"
  14. slug="${slug%%-}"
  15. slug="${slug:0:$max_length}"
  16. date="$(date '+%Y-%m-%d')"
  17. file="$cwd/blog/$date-$slug.org"
  18. longdate="$(date -R)"
  19. if [ -f "$file" ]; then
  20. echo "A post with that title already exists from today's date."
  21. exit 1
  22. fi
  23. echo "#+TITLE: $title" >> "$file"
  24. echo "#+DATE: <$longdate>" >> "$file"
  25. echo >> "$file"
  26. echo "Created: $file"
  27. echo "Done."
  28. emacsclient -n $file