From f2695ca43192fc0432b87a5f24de26d1cb3b8d04 Mon Sep 17 00:00:00 2001 From: Jeffrey Date: Wed, 5 Aug 2026 16:53:25 +0800 Subject: [PATCH] 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. --- .zshrc | 51 ++++++++++++++++++++++++++++++++++++++-------- README.md | 28 +++++++++++++++++-------- zshrc/personal.zsh | 11 ---------- 3 files changed, 61 insertions(+), 29 deletions(-) delete mode 100644 zshrc/personal.zsh diff --git a/.zshrc b/.zshrc index 9110086..380dc5f 100644 --- a/.zshrc +++ b/.zshrc @@ -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 diff --git a/README.md b/README.md index e92f0c1..1ec5f13 100644 --- a/README.md +++ b/README.md @@ -14,27 +14,37 @@ Options: `--cp-hist` / `-c` imports bash history; `--non-interactive` / `-n` skips the default-shell change. The installer backs up an existing `~/.zshrc` and `~/.zshenv` before replacing them. +## What gets installed where + +| Path | Role | +| --- | --- | +| `~/.zshrc` | Canonical shell entry (from repo `.zshrc`). Stay close to upstream; reinstall overwrites it. | +| `~/.zshenv` | Early env for every zsh (Homebrew `shellenv` on macOS). | +| `~/.config/zshrc/*.zsh` | Your overlays, sourced by `~/.zshrc` **before** oh-my-zsh loads. | + +Do not put personal tweaks into `~/.zshrc` if you want painless upgrades: put them under `~/.config/zshrc/` instead. + ## Personal configuration -`~/.zshrc` is meant to stay close to this repo's canonical version. Put your own -tweaks in `~/.config/zshrc/` instead of editing `~/.zshrc` directly: every -`*.zsh` file there is sourced near the end of `~/.zshrc`, just before oh-my-zsh -loads, so it can add plugins and override defaults. +Every `*.zsh` file in `~/.config/zshrc/` is sourced near the end of `~/.zshrc`, +just before oh-my-zsh loads, so it can add plugins and override defaults. ```bash -# ~/.config/zshrc/my.zsh -plugins+=(zsh-nvm) # add plugins -plugins=(${plugins:#zsh-autosuggestions}) # or remove one +# ~/.config/zshrc/local.zsh +plugins+=(docker) # add plugins +plugins=(${plugins:#zsh-autosuggestions}) # or remove one alias gs='git status' ``` -Ready-made configs from this repo's `zshrc/` directory (`fnm`, `nvm`, `pyenv`, -`merlin_devbox`, `merlin_worker`, `personal`, `p10k`) can be pulled in by name: +Ready-made **tool** configs from this repo's `zshrc/` directory can be pulled in +by name (not personal samples): ```bash curl -fsSL https://git.miomio.moe/mio/easyzsh/raw/branch/master/patch.sh | bash -s -- fnm pyenv ``` +Current fragments: `fnm`, `nvm`, `pyenv`, `p10k`, `merlin_devbox`, `merlin_worker`. + Because these files load before oh-my-zsh, plugin and theme changes take effect; aliases that must beat oh-my-zsh's own should be defined after oh-my-zsh loads (see the note in `~/.zshrc`). diff --git a/zshrc/personal.zsh b/zshrc/personal.zsh deleted file mode 100644 index be2d74e..0000000 --- a/zshrc/personal.zsh +++ /dev/null @@ -1,11 +0,0 @@ - -# This my personal zshrc configs. Feel free to use it and modify according to your needs -# Place all your .zshrc configurations (including this one) in a single or multiple files under ~/.config/ezsh/zshrc/ folder - -# Additional OH-MY-ZSH plugins to enable -plugins+=(lol httpie docker docker-compose pyenv pip) - -# Remove OH-MY-ZSH plugins from the default config -plugins=(${plugins:#(zsh-autosuggestions|lol)}) - -POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(virtualenv status command_execution_time background_jobs todo ram load rvm time) \ No newline at end of file