Do you alias rm commmand to push-trash, so you can restore/undo your rm ops if done hastly?
What package is this from? I use trash-cli, but don’t have rm aliased (don’t like the way it handles interactive mode).
Not personally, if I accidentally delete something, I restore it from one of my snapshots.
Honestly, I don’t usually use the trash with my GUI file manager.
Correct. It was suggested by Copilot (ChatGPT) AI agent.
trash-cli
I use timeshift too. However, sometime, just undo that rm in an instant could be helpful.
AI Suggeted:
rm() {
# If user explicitly uses -rf or -f, do real rm
if [[ "$*" == *"-rf"* || "$*" == *"-f"* ]]; then
/bin/rm "$@"
else
trash-put "$@"
fi
}
alias rrm='/bin/rm'
Restore with fzf pattern matching
restore() {
local trash_dir="$HOME/.local/share/Trash"
local files_dir="$trash_dir/files"
local info_dir="$trash_dir/info"
if [[ -z "$1" ]]; then
echo "Usage: restore <pattern>"
return 1
fi
# Find matching trashed files
local matches=()
while IFS= read -r -d '' file; do
matches+=("$file")
done < <(find "$files_dir" -maxdepth 1 -type f -iname "*$1*" -print0)
if (( ${#matches[@]} == 0 )); then
echo "No trashed files match: $1"
return 1
fi
echo "Found ${#matches[@]} match(es):"
local i=1
for f in "${matches[@]}"; do
echo " [$i] $(basename "$f")"
((i++))
done
# If multiple matches, ask which one
if (( ${#matches[@]} > 1 )); then
read -p "Select file number to restore: " choice
((choice--))
else
choice=0
fi
local file="${matches[$choice]}"
local base="$(basename "$file")"
local info_file="$info_dir/$base.trashinfo"
if [[ ! -f "$info_file" ]]; then
echo "Error: metadata missing for $base"
return 1
fi
# Extract original path
local orig_path
orig_path=$(grep '^Path=' "$info_file" | sed 's/Path=//')
echo "Restoring:"
echo " File: $base"
echo " To: $orig_path"
# Confirm
read -p "Proceed? [y/N] " ans
[[ "$ans" =~ ^[Yy]$ ]] || return 1
# Ensure directory exists
mkdir -p "$(dirname "$orig_path")"
# Move file back
mv "$file" "$orig_path"
# Remove metadata
rm -f "$info_file"
echo "Restored successfully."
}