new 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  2. #This omnipresent conditional is at the beginning of nearly every nci script for checking that current directory is initialized.
  3. if [ ! -d "entries" ]; then
  4. echo "You haven't initialized nci system yet... Please use \"./init\" before posting a new entry."
  5. exit 1
  6. fi
  7. if [ ! -f "user.conf" ]; then
  8. echo "\"user.conf\" file doesn't exist, please run \"./init\" (your existing files won't be affected)"
  9. exit 1
  10. fi
  11. title=""
  12. entry_number=0
  13. next=0
  14. entry_date=$(date +%m-%d-%Y)
  15. #Prompt user for the article title
  16. echo "New article/entry title:"
  17. read -r title
  18. while [ -z "$title" ]; do
  19. echo "Error: Empty title. Please try again:"
  20. read -r title
  21. done
  22. #count created (and deleted) entries
  23. for file in entries/*
  24. do
  25. if [ -f "$file" ]; then
  26. entry_number=$((entry_number+1))
  27. next=$((next+1))
  28. fi
  29. done
  30. entry_number=$((entry_number-1)) #exclude README file
  31. editor=""
  32. #create the new entry file
  33. touch "entries/entry_$next"
  34. echo "TITLE:$title
  35. DATE:$entry_date
  36. BODY:" >> entries/entry_$next
  37. #read preferred editor
  38. read -r editor < "user.conf"
  39. eval "$editor entries/entry_$next"
  40. echo "-------------------------------------------------"
  41. echo "ENTRY_ID = $next"
  42. echo "TITLE: $title"
  43. echo "DATE: $entry_date"
  44. echo "Article successfully created! REMEMBER: Use \"./refresh\" to insert your new entries into HTML and RSS files."
  45. echo "-------------------------------------------------"