Dotfiles for my tiling window manager + terminal workflow.
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.

40 lines
1.1 KiB

  1. #!/bin/bash
  2. # Delete TeX build files when exiting from Vim or call on directory/directly to
  3. # remove from there.
  4. ext_list="/home/kevin/linux-config/txt/tex-build-files.txt"
  5. raw_exts="$(tr '\n' '|' < $ext_list)"
  6. exts="(${raw_exts::-1})"
  7. echo "$exts"
  8. find_flags=(-maxdepth 1 -type f -regextype gnu-awk -regex)
  9. remove_build_files () {
  10. regex=$2
  11. # echo find "$1" "${find_flags[@]}" "$regex" -delete -print
  12. eval find "$1" "${find_flags[@]}" "$regex" -delete -print
  13. }
  14. # when less than one argument, remove build files in current dir
  15. if [[ "$#" -lt 1 ]]; then
  16. regex=(\"^.*\\."$exts"$\")
  17. remove_build_files . "${regex[0]}"
  18. else
  19. case "$1" in
  20. # if tex file, remove only build files for that file
  21. *.tex)
  22. file=$(readlink -f "$1")
  23. dir=$(dirname "$file")
  24. base="${file%.*}"
  25. regex=(\"^"$base"\\."$exts"$\")
  26. remove_build_files "$dir" "${regex[0]}" ;;
  27. # remove all build files in directory if given valid one
  28. *)
  29. if [[ -d "$1" ]]; then
  30. regex=(\"^.*\\."$exts"$\")
  31. remove_build_files "$1" "${regex[0]}"
  32. else
  33. printf "Give .tex file or directory as argument.\\n"
  34. fi ;;
  35. esac
  36. fi