Last active
May 27, 2025 14:04
-
-
Save QNimbus/17fcdf7c6de5d9f9d2b4a23f3deed1ac to your computer and use it in GitHub Desktop.
Bash aliases #shell #bash #linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Safe replacement for 'rm' | |
function rm() { | |
# Check if trash-put is available | |
if ! command -v trash-put >/dev/null 2>&1; then | |
echo -e "โ 'trash-put' not found! Nothing was deleted." | |
echo -e "๐ก You can install it with:\n\n sudo apt-get update && sudo apt-get install trash-cli\n" | |
return 1 | |
fi | |
local args=() | |
local skipped_opts=() | |
local missing=() | |
# Separate options from actual file/folder arguments | |
for arg in "$@"; do | |
if [[ "$arg" == -* ]]; then | |
skipped_opts+=("$arg") | |
elif [[ -e "$arg" ]]; then | |
args+=("$arg") | |
else | |
missing+=("$arg") | |
fi | |
done | |
if [[ ${#args[@]} -eq 0 ]]; then | |
echo -e "โ ๏ธ 'rm' was called but no valid files or directories were found to delete." | |
if [[ ${#missing[@]} -gt 0 ]]; then | |
echo -e "โ Skipped missing/nonexistent: ${missing[*]}" | |
fi | |
return 1 | |
fi | |
echo -e "โ ๏ธ 'rm' has been overridden! Using 'trash-put' instead to safely delete:โ ${args[*]}" | |
echo | |
# Show available safe deletion aliases | |
echo -e "๐ก Available safe deletion aliases:" | |
echo -e " ๐๏ธ del โ trash-put" | |
echo -e " ๐๏ธ rmdir โ trash-put" | |
echo -e " โป๏ธ undo / undel โ trash-restore" | |
echo -e " ๐ trash โ trash-list" | |
echo -e " ๐ฎ emptytrash โ trash-empty" | |
echo -e " ๐ฅ realrm โ use real '/bin/rm' (โ ๏ธ irreversible!)" | |
echo | |
echo -e "๐ฆ Executing: trash-put ${args[*]}" | |
echo | |
trash-put "${args[@]}" | |
} | |
# Optional aliases for convenience | |
alias del='trash-put' | |
alias rmdir='trash-put' | |
alias emptytrash='trash-empty' | |
alias undo='trash-restore' | |
alias undel='trash-restore' | |
alias trash='trash-list' | |
alias realrm='/bin/rm' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment