Skip to content

Commit efc4699

Browse files
authored
refactor: clean up unneeded call (#17)
- Remove unnecessary /bin/rm "$@" call - Fix undefined $home_mount variable - Add confirmation before empty-trashy
1 parent d5b47ec commit efc4699

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

rm-safely

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ get_all_trash_dirs() {
6969
trash_dirs+=("${HOME}/.local/share/Trash")
7070
fi
7171
72+
local home_mount=$(get_mount_point "$HOME")
7273
local uid=$(id -u)
73-
for mount in $(df -h | tail -n +2 | awk '{print $NF}' | grep -v "^/$home_mount$"); do
74+
for mount in $(df -h | tail -n +2 | awk '{print $NF}' | grep -v "^${home_mount}$"); do
7475
if [ -d "${mount}/.Trash-${uid}" ]; then
7576
trash_dirs+=("${mount}/.Trash-${uid}")
7677
fi
@@ -157,6 +158,14 @@ rm() {
157158
/bin/rm "$@"
158159
;;
159160
--empty-trash)
161+
echo "WARNING: Permanently delete all files in trash?"
162+
echo -n "Type 'yes' to confirm: "
163+
read -r response
164+
if [ "$response" != "yes" ]; then
165+
echo "Cancelled."
166+
return 1
167+
fi
168+
160169
local found_trash=0
161170
while IFS= read -r trash_dir; do
162171
if [ -d "$trash_dir/files" ] && [ -n "$(ls -A "$trash_dir/files" 2>/dev/null)" ]; then
@@ -392,10 +401,6 @@ HELP
392401
fi
393402
done
394403
395-
if [ $failed -eq 0 ]; then
396-
/bin/rm "$@" 2>/dev/null || true
397-
fi
398-
399404
return $failed
400405
;;
401406
esac

0 commit comments

Comments
 (0)