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:
@@ -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
|
||||
|
||||
@@ -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`).
|
||||
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user