bisect.sh 968 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. mkdir -p mods-bisect/
  2. blacklist='(geckolib|trinkets|architectury|owo|badpackets|patchouli|qsl|fabric-language-kotlin|feature_nbt_deadlock|cloth-config)'
  3. if [ "$1" = 'remove' ]; then
  4. ls_command='ls mods/*.jar'
  5. mv_command='mv {} mods-bisect/'
  6. elif [ "$1" = 'return' ]; then
  7. ls_command='ls mods-bisect/*.jar'
  8. mv_command='mv {} mods/'
  9. else
  10. echo "Usage: ./bisect.sh [remove|return] [upper|lower] <amount>"
  11. exit 1
  12. fi
  13. if [ -n "$3" ]; then
  14. move_count="$3"
  15. else
  16. move_count="$(eval "$ls_command" | wc --lines)"
  17. move_count="$((move_count / 2))"
  18. fi
  19. if [ "$2" = 'upper' ]; then
  20. filter_command="head -n$move_count"
  21. elif [ "$2" = 'lower' ]; then
  22. filter_command="tail -n$move_count"
  23. else
  24. echo "Usage: ./bisect.sh [remove|return] [upper|lower] <amount>"
  25. exit 1
  26. fi
  27. eval "$ls_command" \
  28. | grep -E --invert-match --ignore-case "$blacklist" \
  29. | eval "$filter_command" \
  30. | xargs --verbose --delimiter='\n' -I '{}' \
  31. $mv_command
  32. printf 'Moved %s files' "$move_count"