update_funcs.sh 778 B

12345678910111213141516171819202122232425262728293031
  1. #!/bin/bash
  2. function set_today
  3. {
  4. local today_path="$(date +%Y)/$(date +%m)/$(date +%d)/"
  5. # If the folder doesn't exist, then create it.
  6. if [[ ! -d $today_path ]]; then
  7. mkdir -p "$today_path"
  8. fi
  9. if [[ -a Today ]]; then
  10. local today_link=$(stat -c %N Today | sed -n -e "s/.* -> '\(.*\)'/\1/p")
  11. # Is the Today symlink already pointing to todays folder?
  12. if [[ $today_path == $today_link ]]; then
  13. echo "Already today!";
  14. return 0
  15. fi
  16. # Copy all unfinished tasks to today.
  17. if [[ -n $(ls Today/ | grep -G '.*\.description$') ]]; then
  18. cp -P Today/*.description "$today_path"
  19. fi
  20. unlink Today
  21. fi
  22. # Update the symlink
  23. ln -s "$today_path" Today
  24. }