compile.sh 778 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. # unset -v latest
  4. # for file in "$dir"/*; do
  5. # [[ $file -nt $latest ]] && latest=$file
  6. # done
  7. compile_java(){
  8. file="$1"
  9. no_ext="${file%.*}"
  10. # find jar files and add it to the arguments
  11. for jar in *.jar; do
  12. [[ -z ${cmd:-} ]] && cmd="-cp ."
  13. cmd+=":${jar}"
  14. done
  15. javac $cmd "$file" && java $cmd "$no_ext"
  16. }
  17. dir=$(dirname "$1")
  18. echo $dir
  19. recent=$(find "$dir" -type f -mtime 0 | head -n1)
  20. ext="${1##*.}"
  21. case "$ext" in
  22. py) python3 "$1" && black "$1" ;;
  23. cpp) cd "$dir" && g++ "$1" && ./a.out ;;
  24. sh) sh "$1" ;;
  25. lisp) clisp "$1" ;;
  26. java) compile_java "$@";;
  27. tex) pdflatex -interaction nonstopmode "$1" ;;
  28. *) echo "Unrecognized extension: ${ext}" ;;
  29. esac