several bug fix
This commit is contained in:
@@ -99,6 +99,7 @@ expandlist()
|
||||
continue
|
||||
fi
|
||||
|
||||
local content
|
||||
for content in "${expanded[@]}"; do
|
||||
if (( matched )); then
|
||||
result+="$separator"
|
||||
@@ -106,6 +107,7 @@ expandlist()
|
||||
result+="\"$content\""
|
||||
matched=1
|
||||
done
|
||||
unset content
|
||||
done
|
||||
|
||||
shopt -u nullglob
|
||||
@@ -182,6 +184,7 @@ clean()
|
||||
(( ! recursive )) && findopt=(-maxdepth 1)
|
||||
(( ! force )) && rmopt=(-i)
|
||||
|
||||
local dir f
|
||||
for dir in "${dirlist[@]}"; do
|
||||
find "$dir" "${findopt[@]}" -type f \( -name "*~" -o -name "#*#" -o -name "*.bak" -o -name ".~*#" \) -print0 |
|
||||
while IFS= read -r -d '' f; do
|
||||
@@ -191,10 +194,18 @@ clean()
|
||||
else
|
||||
printf 'rm -- "%s"\n' "$f"
|
||||
fi
|
||||
elif (( force )); then
|
||||
# No confirmation: rm reads no stdin, so leave it attached
|
||||
# to the find pipe (a /dev/tty redirect would fail when there
|
||||
# is no controlling terminal, e.g. cron).
|
||||
rm -- "$f" || disp E "Failed to remove \"$f\"."
|
||||
else
|
||||
rm "${rmopt[@]}" -- "$f"
|
||||
# Interactive rm -i: read the answer from the terminal, not
|
||||
# from the find pipe that feeds this loop's stdin.
|
||||
rm -i -- "$f" </dev/tty || disp E "Failed to remove \"$f\"."
|
||||
fi
|
||||
done
|
||||
unset f
|
||||
done
|
||||
}
|
||||
export -f clean
|
||||
@@ -214,7 +225,7 @@ mcd()
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ ! $# -eq 1 ]]; then
|
||||
if (( $# != 1 )); then
|
||||
disp E "Missing parameter. Use \"mcd --help\" to display usage."
|
||||
return 1
|
||||
fi
|
||||
@@ -247,7 +258,7 @@ rmspc()
|
||||
local mvopt=()
|
||||
local PARSED
|
||||
|
||||
PARSED=$(getopt -o hr:c::vs --long help,recursive,subst-char::,verbose,shell -n 'rmspc' -- "$@")
|
||||
PARSED=$(getopt -o hrc::vs --long help,recursive,subst-char::,verbose,shell -n 'rmspc' -- "$@")
|
||||
# shellcheck disable=SC2181 # getopt return code is checked immediately after
|
||||
if [[ $? -ne 0 ]]; then
|
||||
disp E "Invalid options, use \"rmspc --help\" to display usage."
|
||||
@@ -302,6 +313,7 @@ rmspc()
|
||||
(( verb )) && mvopt=(-v)
|
||||
|
||||
shopt -s nullglob
|
||||
local f
|
||||
for f in *; do
|
||||
if (( recurs )) && [[ -d "$f" ]]; then
|
||||
(
|
||||
@@ -309,11 +321,14 @@ rmspc()
|
||||
(( verb )) && disp I "Entering directory $(pwd)/$f ..."
|
||||
pushd "$f" >/dev/null || return 1
|
||||
|
||||
if (( substchar_set )); then
|
||||
rmspc ${recurs:+-r} -c "$substchar" ${verb:+-v} ${shell:+-s}
|
||||
else
|
||||
rmspc ${recurs:+-r} ${verb:+-v} ${shell:+-s}
|
||||
fi
|
||||
# Build the recursive argument list by value: the ${var:+-flag}
|
||||
# idiom would expand on the *string* "0" (non-empty) and wrongly
|
||||
# force -v/-s on every recursive call.
|
||||
local rargs=(-r)
|
||||
(( verb )) && rargs+=(-v)
|
||||
(( shell )) && rargs+=(-s)
|
||||
(( substchar_set )) && rargs+=(-c "$substchar")
|
||||
rmspc "${rargs[@]}"
|
||||
|
||||
popd >/dev/null || return 1
|
||||
(( verb )) && disp I "Leaving directory $(pwd)/$lastdir"
|
||||
@@ -337,6 +352,7 @@ rmspc()
|
||||
fi
|
||||
fi
|
||||
done
|
||||
unset f
|
||||
shopt -u nullglob
|
||||
}
|
||||
export -f rmspc
|
||||
@@ -462,15 +478,19 @@ file_stats()
|
||||
fi
|
||||
|
||||
# Extension list filter
|
||||
local exts
|
||||
if [[ -n "$ext_list" ]]; then
|
||||
IFS=',' read -ra exts <<< "$ext_list"
|
||||
find_cmd+=('(')
|
||||
local i
|
||||
for i in "${!exts[@]}"; do
|
||||
[[ $i -ne 0 ]] && find_cmd+=(-o)
|
||||
find_cmd+=(-iname "*.${exts[$i]}")
|
||||
done
|
||||
unset i
|
||||
find_cmd+=(')')
|
||||
fi
|
||||
unset exts
|
||||
|
||||
# Minimum/maximum size filters (evaluated in bytes)
|
||||
if [[ -n "$min_size" || -n "$max_size" ]]; then
|
||||
@@ -653,22 +673,26 @@ findbig()
|
||||
(( one_fs )) && _fd_args+=(--one-file-system)
|
||||
_fd_args+=(. "$dir")
|
||||
if (( details )); then
|
||||
local line
|
||||
"$_fd" "${_fd_args[@]}" --exec stat --printf="%s %n\n" 2>/dev/null \
|
||||
| sort -rn | head -n "$limit" \
|
||||
| while IFS= read -r line; do
|
||||
local path="${line#* }"
|
||||
ls -ld -- "$path"
|
||||
done
|
||||
unset line
|
||||
else
|
||||
"$_fd" "${_fd_args[@]}" --exec stat --printf="%s %n\n" 2>/dev/null \
|
||||
| sort -rn | head -n "$limit"
|
||||
fi
|
||||
elif (( details )); then
|
||||
local line
|
||||
find "${find_args[@]}" -printf "%s %p\n" 2>/dev/null | sort -rn | head -n "$limit" |
|
||||
while IFS= read -r line; do
|
||||
local path="${line#* }"
|
||||
ls -ld -- "$path"
|
||||
done
|
||||
unset line
|
||||
else
|
||||
find "${find_args[@]}" -printf "%s %p\n" 2>/dev/null | sort -rn | head -n "$limit"
|
||||
fi
|
||||
@@ -748,14 +772,18 @@ findzero()
|
||||
_fd_args+=(. "$dir")
|
||||
if (( delete )); then
|
||||
disp W "Deleting empty files in $dir..."
|
||||
local f
|
||||
"$_fd" "${_fd_args[@]}" 2>/dev/null | while IFS= read -r f; do
|
||||
printf "%s\n" "$f"
|
||||
rm -f -- "$f"
|
||||
done
|
||||
unset f
|
||||
elif (( details )); then
|
||||
local f
|
||||
"$_fd" "${_fd_args[@]}" 2>/dev/null | while IFS= read -r f; do
|
||||
ls -ls -- "$f"
|
||||
done
|
||||
unset f
|
||||
else
|
||||
"$_fd" "${_fd_args[@]}" 2>/dev/null
|
||||
fi
|
||||
@@ -843,17 +871,23 @@ finddead()
|
||||
_fd_args+=(. "$dir")
|
||||
if (( delete )); then
|
||||
disp W "Deleting dead symlinks in $dir..."
|
||||
local f
|
||||
"$_fd" "${_fd_args[@]}" 2>/dev/null | while IFS= read -r f; do
|
||||
[[ -e "$f" ]] || { printf "%s\n" "$f"; rm -f -- "$f"; }
|
||||
done
|
||||
unset f
|
||||
elif (( details )); then
|
||||
local f
|
||||
"$_fd" "${_fd_args[@]}" 2>/dev/null | while IFS= read -r f; do
|
||||
[[ -e "$f" ]] || ls -ls -- "$f"
|
||||
done
|
||||
unset f
|
||||
else
|
||||
local f
|
||||
"$_fd" "${_fd_args[@]}" 2>/dev/null | while IFS= read -r f; do
|
||||
[[ -e "$f" ]] || printf "%s\n" "$f"
|
||||
done
|
||||
unset f
|
||||
fi
|
||||
elif (( delete )); then
|
||||
disp W "Deleting dead symlinks in $dir..."
|
||||
|
||||
Reference in New Issue
Block a user