diff --git a/.local/bin/scripts/clean b/.local/bin/scripts/clean index 7125eb3..d970c7d 100755 --- a/.local/bin/scripts/clean +++ b/.local/bin/scripts/clean @@ -21,7 +21,7 @@ find "$dir" -maxdepth 2 -not -name ".stfolder" -empty -printf "Removing empty %p find -L -maxdepth 2 -type l -printf "Removing broken symlink %p\n" -delete highlight "e :: recursively remove empty folders and files" -[[ $1 =~ "e" ]] && find -empty -not -name ".stfolder" -empty -printf "Removing empty %p\n" -delete +[[ $1 =~ "e" ]] && find \( -name ".stfolder" -o -name ".*keep" -o -name ".git" \) -prune -o -empty -printf "Removing empty %p\n" -exec rm -d {} + for k in "${!_clean_map[@]}"; do folder="${_clean_map[$k]}" @@ -49,9 +49,10 @@ if [[ $1 =~ "d" ]]; then -type d \( -name 'cache' $(echo $DIRS_GENERATED | sed 's|-x \([^ ]\+\)|-o -name \1|g') \) \ -print -exec rm $i -r {} + -prune echo -n " " && highlight "build directories" - find \( -name ".git" -o -path "*/mixxx/build" -o -name "Leaflet" -o -name "www" -o -name "src" \) \ + find \( -name ".git" -o -path "*/mixxx/build" -o -name "app" -o -name "Leaflet" -o -name "www" -o -name "src" \) \ -prune -o -name "build" -type d \ -print -exec rm -rI {} + -prune + # TODO consider gitignore / use git clean fi highlight "g :: clean gradle caches" if [[ $1 =~ "g" ]]; then @@ -61,7 +62,7 @@ fi highlight "c :: clean electron caches" [[ $1 =~ "c" ]] && find "$dir$(expr "${XDG_CONFIG_HOME/$HOME}" \| "/.config")" \ - -type d -name "*Cache" -print -exec rm $i -r {} + -prune + -type d -name "*Cache*" -print -exec rm $i -r {} + -prune if test -f "/var/log/apt/history.log"; then aptclean_cur=$(cat "/var/log/apt/history.log" | wc -l) diff --git a/.local/bin/scripts/delbig b/.local/bin/scripts/delbig index ca5abb8..ec59b32 100755 --- a/.local/bin/scripts/delbig +++ b/.local/bin/scripts/delbig @@ -1,3 +1,3 @@ #!/bin/sh # Find and remove sizeable files -find -size +5M -print -exec rm -I {} + +find -size +${1:-50}M -exec rm -vi {} + diff --git a/.local/bin/scripts/denest b/.local/bin/scripts/denest index 165af13..c469f37 100755 --- a/.local/bin/scripts/denest +++ b/.local/bin/scripts/denest @@ -1,3 +1,12 @@ -#!/bin/sh -# Remove one level of folders -find -mindepth 1 -maxdepth 1 -exec sh -c 'mv -nv {}/* . && rm -dv {}' \; +#!/bin/sh -e +# Flatten folder hierarchy +# Args: depth +find -mindepth 2 -maxdepth ${depth:-2} -depth -type d "$@" | while read folder; do + newname="$(echo "$folder" | sed 's|^./||;s|/|_|g')" + mv -v "$folder" "$newname" + parent="$(dirname "$folder")" + test "$(basename "$folder")" = "$(basename "$parent")" && + rm -d "$parent" && + mv -v "$newname" "$parent" +done +find -maxdepth ${depth:-2} -empty -type d -delete diff --git a/.local/bin/scripts/duploc b/.local/bin/scripts/duploc index a2f378a..0503069 100755 --- a/.local/bin/scripts/duploc +++ b/.local/bin/scripts/duploc @@ -1,11 +1,11 @@ #!/bin/sh -e # Delete files under current or given path which exist elsewhere as listed in the locate database # Matches first by name, then by checksum (currently inefficiently via md5) -case "$1" in ([0-9]) size=$1; shift;; esac -find "$@" -size +${size:-5}M -type f -exec sh -c "IFS=$'\n'"' +case $1 in ([0-9]|[0-9][0-9]) threshold=$1; shift;; esac +find "$@" -size +${threshold:-50}M -type f -exec sh -c "IFS=$'\n'"' filepath="{}" target="$(basename "$filepath" | synct-unarchive)" highlight "$filepath" for existing in $(locate -b "$target") - do test "$(realpath "$target")" != "$(realpath "$existing")" -a -f "$existing" -a "$(md5sum "$existing" | cut -d\ -f1)" = "$(md5sum "$filepath" | cut -d\ -f1)" && echo "Found duplicate at $existing" && rm -vi "$filepath" && break + do test "$(realpath "$target")" != "$(realpath "$existing")" -a -f "$existing" && test "$(md5sum "$existing" | cut -d\ -f1)" = "$(md5sum "$filepath" | cut -d\ -f1)" && echo "Found duplicate at $existing" && rm -vi "$filepath" && break done' \;