feat(shell): add .zshenv Homebrew init and Trash-backed rm

Move brew shellenv into .zshenv so PATH is available outside
interactive shells, and make install guarantee a Trash backend
for safer rm aliases on both macOS and Linux.
This commit is contained in:
mio
2026-07-26 16:28:09 +08:00
parent 17ecc5f67c
commit 9377023e28
4 changed files with 62 additions and 15 deletions
+30 -8
View File
@@ -56,6 +56,14 @@ run_as_root() {
fi
}
has_trash_command() {
if [[ "$OSTYPE" == darwin* ]]; then
command -v trash &> /dev/null || command -v rmtrash &> /dev/null
else
command -v gio &> /dev/null || command -v trash-put &> /dev/null
fi
}
install_eza_binary() {
local archive
local binary
@@ -177,19 +185,20 @@ install_packages() {
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
brew install "${base_packages[@]}"
command -v trash &> /dev/null || brew install rmtrash
;;
ubuntu|debian)
run_as_root apt-get update
run_as_root apt-get install -y "${base_packages[@]}" curl tar
run_as_root apt-get install -y "${base_packages[@]}" curl tar libglib2.0-bin
;;
fedora)
run_as_root dnf install -y "${base_packages[@]}" curl tar
run_as_root dnf install -y "${base_packages[@]}" curl tar glib2
;;
centos|rhel)
run_as_root yum install -y "${base_packages[@]}" curl tar
run_as_root yum install -y "${base_packages[@]}" curl tar glib2
;;
arch|manjaro)
run_as_root pacman -Syu --noconfirm "${base_packages[@]}" curl tar
run_as_root pacman -Syu --noconfirm "${base_packages[@]}" curl tar glib2
;;
*)
echo "Unsupported operating system. Please install ${base_packages[*]} manually."
@@ -207,15 +216,20 @@ install_packages() {
return 1
fi
done
if ! has_trash_command; then
echo "Error: no command is available for moving files to Trash" >&2
return 1
fi
}
# Check if required packages are installed, if not, install them
if command -v zsh &> /dev/null && command -v git &> /dev/null && command -v wget &> /dev/null && command -v curl &> /dev/null && command -v tar &> /dev/null && command -v fc-cache &> /dev/null && command -v eza &> /dev/null && command -v zoxide &> /dev/null && command -v autoconf &> /dev/null; then
echo -e "ZSH, Git, wget, curl, tar, fontconfig, eza, zoxide, and autoconf are already installed\n"
if command -v zsh &> /dev/null && command -v git &> /dev/null && command -v wget &> /dev/null && command -v curl &> /dev/null && command -v tar &> /dev/null && command -v fc-cache &> /dev/null && command -v eza &> /dev/null && command -v zoxide &> /dev/null && command -v autoconf &> /dev/null && has_trash_command; then
echo -e "ZSH, Git, wget, curl, tar, fontconfig, eza, zoxide, autoconf, and Trash support are already installed\n"
else
echo "Installing required packages..."
install_packages
echo -e "zsh, wget, curl, tar, git, fontconfig, eza, zoxide, and autoconf installed\n"
echo -e "zsh, wget, curl, tar, git, fontconfig, eza, zoxide, autoconf, and Trash support installed\n"
fi
if [ -f ~/.gitconfig.backup ]; then
@@ -229,8 +243,10 @@ fi
ZSH="$HOME/.oh-my-zsh"
zshrc_download=$(mktemp "$HOME/.zshrc.download.XXXXXX")
trap 'rm -f "$zshrc_download"' EXIT
zshenv_download=$(mktemp "$HOME/.zshenv.download.XXXXXX")
trap 'rm -f "$zshrc_download" "$zshenv_download"' EXIT
wget -q "https://git.miomio.moe/mio/easyzsh/raw/branch/master/.zshrc" -O "$zshrc_download"
wget -q "https://git.miomio.moe/mio/easyzsh/raw/branch/master/.zshenv" -O "$zshenv_download"
# echo -e "The setup will be installed in '~/.config/ezsh'\n"
# echo -e "Place your personal zshrc config files under '~/.config/ezsh/zshrc/'\n"
@@ -258,7 +274,13 @@ if [ -e "$HOME/.zshrc" ] || [ -L "$HOME/.zshrc" ]; then
cp -Pp "$HOME/.zshrc" "$zshrc_backup"
echo -e "Backed up the current .zshrc to $zshrc_backup\n"
fi
if [ -e "$HOME/.zshenv" ] || [ -L "$HOME/.zshenv" ]; then
zshenv_backup=$(mktemp "$HOME/.zshenv.backup.$(date +"%Y%m%d-%H%M%S").XXXXXX")
cp -Pp "$HOME/.zshenv" "$zshenv_backup"
echo -e "Backed up the current .zshenv to $zshenv_backup\n"
fi
mv "$zshrc_download" "$HOME/.zshrc"
mv "$zshenv_download" "$HOME/.zshenv"
trap - EXIT
# cp -f ezshrc.zsh ~/.config/ezsh/
# cp -f p10k.zsh ~/.config/ezsh/