no count for rm

This commit is contained in:
ville rantanen
2016-07-22 21:49:39 +03:00
parent 7846b82ec6
commit 359a79befb

View File

@@ -4,7 +4,8 @@ set -e
function helpexit() { function helpexit() {
echo Delete files with a progress bar. echo Delete files with a progress bar.
echo This command is always recursive to folders! echo This command is always recursive to folders!
echo '-f to force' echo '-f Dont ask questions'
echo '--nc Dont count files first'
exit exit
} }
@@ -14,6 +15,7 @@ for ((i=1; i<=${#@}; i++)) {
[[ "${!i}" = "-h" ]] && helpexit [[ "${!i}" = "-h" ]] && helpexit
[[ "${!i}" = "--help" ]] && helpexit [[ "${!i}" = "--help" ]] && helpexit
[[ "${!i}" = "-f" ]] && { FORCE=1; RMFORCE="-f"; continue; } [[ "${!i}" = "-f" ]] && { FORCE=1; RMFORCE="-f"; continue; }
[[ "${!i}" = "--nc" ]] && { NOCOUNT=1; continue; }
[[ "${!i}" = "-"* ]] && helpexit [[ "${!i}" = "-"* ]] && helpexit
FOLDERS+=( "${!i%/}" ) FOLDERS+=( "${!i%/}" )
} }
@@ -30,9 +32,9 @@ function deletefiles() {
i=0 i=0
while IFS= read -r -d $'\0' line; do while IFS= read -r -d $'\0' line; do
i=$((i+1)) i=$((i+1))
percent=$((200*$i/$files % 2 + 100*$i/$files)) [[ $files -ne 0 ]] && percent=$((200*$i/$files % 2 + 100*$i/$files))
printf "\r%02d:%02d:%02d %6d/%d %3d%% %s\033[0K" \ printf "\r%02d:%02d:%02d %6d/%d %3d%% %s\033[0K" \
$(($SECONDS/3600)) $(($SECONDS%3600/60)) $(($SECONDS%60)) $i $files $percent "$line" $(($SECONDS/3600)) $(($SECONDS%3600/60)) $(($SECONDS%60)) $i $files "$percent" "$line"
rm "$line" rm "$line"
done < <(find "$@" \( -type f -or -type l \) -print0) done < <(find "$@" \( -type f -or -type l \) -print0)
printf "\n" printf "\n"
@@ -48,9 +50,9 @@ function deletefolders() {
i=0 i=0
while IFS= read -r -d $'\0' line; do while IFS= read -r -d $'\0' line; do
i=$((i+1)) i=$((i+1))
percent=$((200*$i/$folders % 2 + 100*$i/$folders)) [[ $folders -ne 0 ]] && percent=$((200*$i/$folders % 2 + 100*$i/$folders))
printf "\r%02d:%02d:%02d %6d/%d %3d%% %s\033[0K" \ printf "\r%02d:%02d:%02d %6d/%d %3d%% %s\033[0K" \
$(($SECONDS/3600)) $(($SECONDS%3600/60)) $(($SECONDS%60)) $i $folders $percent "$line" $(($SECONDS/3600)) $(($SECONDS%3600/60)) $(($SECONDS%60)) $i $folders "$percent" "$line"
rm -r "$line" rm -r "$line"
done < <(find "$@" -depth -type d -print0) done < <(find "$@" -depth -type d -print0)
printf "\n" printf "\n"
@@ -58,19 +60,22 @@ function deletefolders() {
# stop line wrapping # stop line wrapping
printf '\033[?7l' printf '\033[?7l'
trap "printf '\033[?7h'" 1 9 15 trap "printf '\033[?7h'" 1 9 15
echo Listing files in "${FOLDERS[@]}" ...
files=0 files=0
folders=0 folders=0
listfiles "${FOLDERS[@]}" if [[ "$NOCOUNT" -ne 1 ]]; then
echo Prepared to delete $files files echo Listing files in "${FOLDERS[@]}" ...
listfiles "${FOLDERS[@]}"
echo Prepared to delete $files files
fi
if [[ $FORCE -eq 0 ]]; then if [[ $FORCE -eq 0 ]]; then
echo '<ctrl-c> to quit' echo '<ctrl-c> to quit'
read foo read foo
fi fi
deletefiles "${FOLDERS[@]}" deletefiles "${FOLDERS[@]}"
listfolders "${FOLDERS[@]}" if [[ "$NOCOUNT" -ne 1 ]]; then
echo Removing remaining $folders folders listfolders "${FOLDERS[@]}"
echo Removing remaining $folders folders
fi
deletefolders "${FOLDERS[@]}" deletefolders "${FOLDERS[@]}"
# line wrapping # line wrapping
printf '\033[?7h' printf '\033[?7h'