several bug fix

This commit is contained in:
fatalerrors
2026-07-09 16:04:15 +02:00
parent db7dcb6f03
commit fbe1f074da

View File

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