disk-usage 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env bash
  2. rvm_base_except="selector"
  3. source "$rvm_scripts_path/base"
  4. disk_usage()
  5. {
  6. \typeset directory name _pre
  7. name="$1"
  8. directory="$2"
  9. shift 2
  10. printf "%${length}s" "${name} Usage: "
  11. if [[ -n "$directory" && -d "$directory" && "$directory" != "/" ]]
  12. then
  13. # echo needed to clean spaces (different systems displays this differently)
  14. _pre="$( echo $( du -hs "$@" "${directory}/" ) )"
  15. echo ${_pre%% *}
  16. else
  17. echo "0B"
  18. fi
  19. return 0
  20. }
  21. all_disk_usage()
  22. {
  23. \typeset name
  24. export length=30
  25. for name in archives repos sources logs pkg \
  26. rubies gemsets wrappers temporary others total
  27. do
  28. ${name}_disk_usage
  29. done
  30. }
  31. archives_disk_usage() { disk_usage "Downloaded Archives" "archives"; }
  32. docs_disk_usage() { disk_usage "Documentation" "docs"; }
  33. repos_disk_usage() { disk_usage "Repositories" "repos"; }
  34. sources_disk_usage() { disk_usage "Extracted Source Code" "src"; }
  35. logs_disk_usage() { disk_usage "Log Files" "log"; }
  36. pkg_disk_usage() { disk_usage "Packages" "usr"; }
  37. rubies_disk_usage() { disk_usage "Rubies" "rubies"; }
  38. gemsets_disk_usage() { disk_usage "Gemsets" "gems"; }
  39. wrappers_disk_usage() { disk_usage "Wrappers" "wrappers"; }
  40. temporary_disk_usage() { disk_usage "Temporary Files" "tmp"; }
  41. total_disk_usage() { disk_usage "Total Disk" "."; }
  42. others_disk_usage()
  43. {
  44. \typeset flag filter
  45. \typeset -a flags
  46. if du --exclude=* . 2>/dev/null 1>/dev/null
  47. then flag="--exclude="
  48. else flag="-I "
  49. fi
  50. for filter in archives docs repos src log usr rubies gems wrappers tmp
  51. do flags+=( ${flag}${filter} )
  52. done
  53. disk_usage "Other Files" "." "${flags[@]}"
  54. }
  55. case "${1:-help}" in
  56. all|total|archives|docs|repos|sources|logs|pkg|rubies|gemsets|wrappers|tmp|others)
  57. (
  58. export length=""
  59. __rvm_cd $rvm_path
  60. $1_disk_usage
  61. )
  62. ;;
  63. help|*)
  64. rvm_help disk-usage
  65. ;;
  66. esac