diff --git a/delete_Trash-1000.sh b/delete_Trash-1000.sh index 99a0606..3a0cd89 100644 --- a/delete_Trash-1000.sh +++ b/delete_Trash-1000.sh @@ -1,7 +1,21 @@ #!/bin/bash -# Ask the user for the path to the folder -read -p "Enter the path to the folder: " folder_path +# Initialize variables +auto_confirm=false + +# Parse arguments for the folder path and the -y option +while [[ "$#" -gt 0 ]]; do + case "$1" in + -y) auto_confirm=true ;; + *) folder_path="$1" ;; + esac + shift +done + +# If no folder path is provided, prompt the user for it +if [ -z "$folder_path" ]; then + read -p "Enter the path to the folder: " folder_path +fi # Check if the provided path is valid if [ ! -d "$folder_path" ]; then @@ -21,19 +35,21 @@ else echo "$trash_folders" echo - # Ask for confirmation before deletion - read -p "Do you really want to delete all these folders? (y/n): " confirmation - - if [[ "$confirmation" == "y" || "$confirmation" == "Y" ]]; then - # Loop through each found folder and delete it while displaying progress - while IFS= read -r folder; do - echo "Deleting folder: $folder" - rm -rf "$folder" - echo "Deleted $folder" - done <<< "$trash_folders" - - echo "All .Trash-1000 folders have been deleted." - else - echo "Deletion canceled." + # Ask for confirmation before deletion if -y is not provided + if [ "$auto_confirm" = false ]; then + read -p "Do you really want to delete all these folders? (y/n): " confirmation + if [[ "$confirmation" != "y" && "$confirmation" != "Y" ]]; then + echo "Deletion canceled." + exit 0 + fi fi + + # Loop through each found folder and delete it + while IFS= read -r folder; do + echo "Deleting folder: $folder" + rm -rf "$folder" + echo "Deleted $folder" + done <<< "$trash_folders" + + echo "All .Trash-1000 folders have been deleted." fi