mod 935 B

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/bash
  2. if [ ! -d "entries" ]; then
  3. echo "You haven't initialized nci system yet... Please use \"./init\" before editing entries."
  4. exit 1
  5. fi
  6. if [ ! -f "user.conf" ]; then
  7. echo "\"user.conf\" file doesn't exist, please run \"./init\" (your existing files won't be affected)"
  8. exit 1
  9. fi
  10. #check if no id entered.
  11. if [ -z "$1" ]; then
  12. echo "Error: Please type the ID of the entry you want to edit (Usage: \"./mod <entry_id>\")."
  13. exit 1
  14. fi
  15. editor=""
  16. read -r editor < "user.conf"
  17. #check if entry is not deleted, if exists, open the editor
  18. if [ -f "entries/entry_$1" ]; then
  19. contents=$(cat "entries/entry_$1")
  20. if [ "$contents" = "[DELETED]" ]; then
  21. echo "Error: That entry is deleted."
  22. exit 1
  23. else
  24. #change this for your favorite text editor if u want
  25. eval "$editor entries/entry_$1"
  26. echo "Remember to run \"./refresh\" to save changes."
  27. fi
  28. else
  29. echo "Error: That entry doesn't exist."
  30. fi