#!/bin/bash set -euo pipefail # Install tool fragments from this repo into ~/.config. # # Bare name → zshrc/.zsh → ~/.config/zshrc/.zsh (interactive) # Path form → .zsh → ~/.config/.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