Files
easyzsh/patch.sh
T
Frank Qing 9257eceb47 fix(pyenv): load managed Python in every zsh
The pyenv fragment lived in the interactive overlay, so agents and zsh -c fell back to system Python. Install it through the always-on fragment path and keep XDG destinations aligned with the loader.
2026-08-07 18:14:22 +08:00

49 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
# Install tool fragments from this repo into ~/.config.
#
# Bare name → zshrc/<name>.zsh → ~/.config/zshrc/<name>.zsh (interactive)
# Path form → <path>.zsh → ~/.config/<path>.zsh
# e.g. zsh/fnm → ~/.config/zsh/fnm.zsh (always-on)
BASE_URL="https://git.miomio.moe/mio/easyzsh/raw/branch/master"
if [ "$#" -eq 0 ]; then
echo "No arguments provided. Please specify the config files to download."
exit 1
fi
for arg in "$@"; do
if [[ "$arg" == */* ]]; then
# Path form: one or more simple segments (zsh/fnm).
if [[ "$arg" == *..* || "$arg" == /* || ! "$arg" =~ ^[A-Za-z0-9_-]+(/[A-Za-z0-9_-]+)+$ ]]; then
echo "Invalid config path: $arg" >&2
exit 1
fi
rel="${arg}.zsh"
destination="${XDG_CONFIG_HOME:-$HOME/.config}/${arg}.zsh"
else
if [[ -z "$arg" || "$arg" == *[![:alnum:]_-]* ]]; then
echo "Invalid config name: $arg" >&2
exit 1
fi
rel="zshrc/${arg}.zsh"
destination="$HOME/.config/zshrc/${arg}.zsh"
fi
mkdir -p "$(dirname "$destination")"
temporary=$(mktemp "$(dirname "$destination")/.easyzsh-XXXXXX")
trap 'rm -f "$temporary"' EXIT
if ! curl -fsSL "${BASE_URL}/${rel}" -o "$temporary"; then
echo "Failed to download ${rel} from ${BASE_URL}"
exit 1
fi
mv "$temporary" "$destination"
trap - EXIT
echo "Installed $destination"
done