diff-tree.sh 727 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. IFS=$'\n\t'
  4. SCRIPT_NAME="${0##*/}"
  5. display_help() {
  6. echo "Usage: ${SCRIPT_NAME} <dir1> <dir2>"
  7. echo "Dependencies: tree diff"
  8. echo "Example:"
  9. echo "- ${SCRIPT_NAME} ~/Downloads ~/Downloads_backup"
  10. echo "- ${SCRIPT_NAME} ./git_repo1 ./git_repo2"
  11. exit 2
  12. }
  13. [[ $# -ne 2 || ! -d $1 || ! -d $2 ]] && display_help
  14. tree_file="/tmp/${SCRIPT_NAME}_tree"
  15. tree_in_dir(){
  16. cd "$1"
  17. tree -dfpiug
  18. }
  19. declare -i index=1
  20. for dir in "$@"; do
  21. tree_in_dir "$dir" > "${tree_file}_${index}"
  22. ((index+=1))
  23. done
  24. diff --color "$tree_file"*
  25. # diff_tree(){
  26. # diff --color \
  27. # <(cd "$dir1"; $tree_cmd) \
  28. # <(cd "$dir2"; $tree_cmd)
  29. # }
  30. # diff_tree