Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
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.

70 lines
1.3KB

  1. #!/bin/sh
  2. ## remove-unused-sources
  3. #
  4. # April 2008, Jonathan Moore Liles
  5. #
  6. # Simple script to scan a compacted Non-DAW session and remove all
  7. # unused sources from disk.
  8. #
  9. # USAGE:
  10. #
  11. # $ remove-unused-sources ~/audio/'The Best Song Ever'
  12. #
  13. # NOTES:
  14. #
  15. # This script will not ask for comfirmation! It will ruthlessly
  16. # delete all unused sources! You have been warned.
  17. #
  18. SESSION="$1"
  19. fatal ()
  20. {
  21. echo Error: "$1"
  22. echo 'Aborting!'
  23. cleanup
  24. exit 1
  25. }
  26. set_diff ()
  27. {
  28. diff --new-line-format '' --old-line-format '%L' --unchanged-line-format '' "$1" "$2"
  29. }
  30. remove_sources ()
  31. {
  32. local FILE
  33. while read FILE
  34. do
  35. echo "Removing source \"${FILE}\"..."
  36. rm -f ./"${FILE}" ./"${FILE}-"*.peak
  37. done
  38. }
  39. cleanup ()
  40. {
  41. rm -f "${TEMP}/all-sources" "${TEMP}/used-sources"
  42. }
  43. cd "$SESSION" || fatal "No such session"
  44. [ -f history ] || fatal "Not a Non-DAW session?"
  45. grep -qv 'create' history && fatal "Not a compacted session"
  46. echo "Scanning \"${SESSION}\"..."
  47. sed -n 's/^Region.* :source "\([^"]\+\)".*$/\1/p' history | sort | uniq > "${TEMP}/used-sources"
  48. cd sources || fatal "Can't change to source directory"
  49. ls -1 | grep -v '\.peak$' | sort > "${TEMP}/all-sources"
  50. set_diff "${TEMP}/all-sources" "${TEMP}/used-sources" | remove_sources
  51. cleanup
  52. echo "Done."