trash 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/sh
  2. # Dont ultrapass header "|"
  3. #-------HEADER-------------------------------------------------------|
  4. #AUTOR:
  5. # Jefferson Rocha <lrcjefferson@gmail.com>
  6. #
  7. #DESCRIPTION:
  8. # Trash is a utility that runs via cli.
  9. #
  10. #USAGE
  11. # trash
  12. #
  13. #CHANGELOG
  14. # (V1.2) 20/03/2018 - Jefferson Rocha
  15. # - Now if you run as root it does not show any more errors!
  16. #
  17. # (V1.3) 14/06/2018 - Jefferson Rocha
  18. # - Now rm remove files and directories started with '-'
  19. #
  20. # (V1.4) 21/12/2018 - Jefferson Rocha
  21. # - Changed wrong word 'Sucessfull' by 'Sucessful'
  22. # - Removed the 'dot' in files size print.
  23. # - Add silence Option
  24. # - Add Help Option
  25. #--------------------------------------------------------------------|
  26. #=================VARS
  27. dir_trash="${HOME}/.local/share/Trash/files/" # Trash Directory
  28. archive_temp="/tmp/random.trash" # Temp Archive
  29. silent="1" # Silence OFF
  30. #=================FUNCTIONS
  31. HELP(){
  32. cat <<EOF
  33. USAGE: trash [OPTION]
  34. Trash is a non-interactive command line utility that cleans the system's trash.
  35. OPTIONS
  36. -q, --quiet
  37. Quiet, ideal for use in cron or halt/boot of your system.
  38. -h, --help
  39. Show this Help.
  40. Author Jefferson 'Slackjeff' Rocha
  41. EMAIL BUGS: < root@slackjeff.com.br >
  42. WEB: < https://notabug.org/jeffersonrocha/trash >
  43. EOF
  44. return 0
  45. }
  46. size_archives(){
  47. cd ${dir_trash} 2>/dev/null && du -hs | sed 's/.$//'> ${archive_temp}
  48. if [ -e "/tmp/random.trash" ]; then
  49. echo -e "\033[34;1mTotal Size:\033[m
  50. $(cat /tmp/random.trash)
  51. ----------------------------------"
  52. fi
  53. # Remove a temp archive
  54. rm "${archive_temp}" 2>/dev/null
  55. }
  56. #=================START
  57. # Checking if user has passed parameter
  58. case $1 in
  59. -q|--silent)
  60. silent="0" # 0 Silent OFF | 1 Silent ON
  61. ;;
  62. -h|--help)
  63. HELP
  64. exit 0
  65. ;;
  66. esac
  67. # Silent on? Ok, verbose now.
  68. if [ "$silent" = "1" ]; then
  69. size_archives # call function
  70. quiet="v"
  71. fi
  72. # directory exist?, bye bye.
  73. if [ -d ${dir_trash} ]; then
  74. ( # Open subshell
  75. cd ${dir_trash} && rm -rf"$quiet" -- * 2>/dev/null
  76. [ "$silent" = "1" ] && echo -e "\033[31;1mSucessful.\033[m"
  77. )
  78. else
  79. echo "Directory '${dir_trash}' not found in system!"
  80. fi