fix(zshrc): safer trash rm wrapper; drop personal install fragment

Keep ~/.zshrc upgrade-friendly by not shipping author-specific
plugin samples as patch targets. Prefer the flag-tolerant trash
function over bare aliases so common rm -f usage still works.
This commit is contained in:
Jeffrey
2026-08-05 16:53:25 +08:00
parent 3fbf8b2350
commit f2695ca431
3 changed files with 61 additions and 29 deletions
+42 -9
View File
@@ -233,15 +233,48 @@ alias ip="ip --color=auto"
alias a='eza -la --git --colour-scale all -g --smart-group --icons always --hyperlink' # the new ls; add --hyperlink if you like
alias aa='eza -la --git --colour-scale all -g --smart-group --icons always -s modified -r --hyperlink' # sort by new
# ponytail: Trash aliases accept paths, not every rm flag; add a wrapper only if flag compatibility is required.
if [[ "$OSTYPE" == darwin* && -x /usr/bin/trash ]]; then
alias rm='/usr/bin/trash'
elif [[ "$OSTYPE" == darwin* ]] && command -v rmtrash &> /dev/null; then
alias rm='rmtrash'
elif [[ "$OSTYPE" != darwin* ]] && command -v gio &> /dev/null; then
alias rm='gio trash'
elif [[ "$OSTYPE" != darwin* ]] && command -v trash-put &> /dev/null; then
alias rm='trash-put'
# rm moves files to Trash while tolerating standard rm flags: -f suppresses
# missing-file errors; other flags are no-ops (trash backends are already
# recursive). Files whose names start with "-" still need /bin/rm.
# Shell snapshots (Claude Code etc.) restore functions but not global arrays,
# so rm() re-resolves the backend when _TRASH_CMD is empty at call time.
_resolve_trash_cmd() {
if [[ "$OSTYPE" == darwin* && -x /usr/bin/trash ]]; then
typeset -ga _TRASH_CMD=(/usr/bin/trash)
elif [[ "$OSTYPE" == darwin* ]] && command -v rmtrash &> /dev/null; then
typeset -ga _TRASH_CMD=(rmtrash)
elif [[ "$OSTYPE" != darwin* ]] && command -v gio &> /dev/null; then
typeset -ga _TRASH_CMD=(gio trash)
elif [[ "$OSTYPE" != darwin* ]] && command -v trash-put &> /dev/null; then
typeset -ga _TRASH_CMD=(trash-put)
fi
}
_resolve_trash_cmd
if (( ${#_TRASH_CMD[@]} )); then
rm() {
(( ${#_TRASH_CMD[@]} )) || _resolve_trash_cmd
(( ${#_TRASH_CMD[@]} )) || { command rm "$@"; return }
local force=0 arg
local -a paths existing
for arg in "$@"; do
case "$arg" in
--) ;;
-*f*) force=1 ;;
-*) ;;
*) paths+=("$arg") ;;
esac
done
(( ${#paths[@]} )) || return 0
if (( force )); then
for arg in "${paths[@]}"; do
[[ -e "$arg" || -L "$arg" ]] && existing+=("$arg")
done
(( ${#existing[@]} )) || return 0
"${_TRASH_CMD[@]}" "${existing[@]}"
else
"${_TRASH_CMD[@]}" "${paths[@]}"
fi
}
fi
# Now source fzf.zsh , otherwise Ctr+r is overwritten by ohmyzsh