Last active
March 3, 2025 06:50
-
-
Save jeremyd2019/4984ff0fa1f6fd8c99d7b8b244c52088 to your computer and use it in GitHub Desktop.
Script to clean up files that msys2-runtime moved to recycle bin because they were in use
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -ex | |
export LC_CTYPE=C.UTF-8 LC_COLLATE=C.UTF-8 | |
IFS=. read -r cygmajor cygminor _ < <(uname -r) | |
declare -a roots | |
if [ "${cygmajor}" -gt 3 -o "${cygmajor}" -eq 3 -a "${cygminor}" -ge 6 ]; then | |
# as of cygwin 3.6, volume roots are parsable from /proc/mounts | |
# (noumount is the option that indicates a cygdrive mount) | |
readarray -t -d $'\0' roots < <( | |
cut -d' ' -f2,4 /proc/mounts | grep '\<noumount\>[^ ]*$' | | |
cut -d' ' -f1 | xargs -d'\n' printf '%b\0') | |
else | |
# before that, just punt and look at the root of the drive / is mounted on | |
root="$(cygpath -w /)" | |
roots=("$(cygpath -u "${root:0:2}")") | |
unset root | |
fi | |
declare -a trash | |
readarray -t -d $'\0' trash < <( | |
LC_CTYPE=C LC_COLLATE=C \ | |
find "${roots[@]}" -maxdepth 1 -iname '$Recycle.Bin' -print0 | | |
LC_CTYPE=C LC_COLLATE=C \ | |
find -files0-from - -maxdepth 2 \( -name $'.\uDC6D\uDC73\uDC79\uDC73*' -o \ | |
-name $'.\uF76D\uF773\uF779\uF773*' -o \ | |
-name '.msys*' -o \ | |
-name $'.\uDC63\uDC79\uDC67*' -o \ | |
-name $'.\uF763\uF779\uF767*' -o \ | |
-name '.cyg*' \) -print0) | |
if (( ${#trash[@]} )); then | |
ls -la "${trash[@]}" | |
read -r -p "Remove? (y/N) " | |
if [[ "${REPLY^^}" == "Y" ]]; then | |
rm -f "${trash[@]}" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment