#!/bin/bash set -e # Function to print usage information usage() { echo "Usage: $0 [-p] [-d directory]" echo " -p Install zsh plugin for rusty-buddy" echo " -d directory Specify an installation directory for the rusty-buddy binary (default: \$HOME/.local/bin)" exit 1 } # Default variables INSTALL_PLUGIN=false BIN_DIR="$HOME/.local/bin" # Parse command-line options while getopts ":pd:" opt; do case $opt in p) INSTALL_PLUGIN=true ;; d) BIN_DIR="$OPTARG" ;; *) usage ;; esac done # Determine the platform OS=$(uname -s) ARCH=$(uname -m) # Map uname output to platform-specific identifiers if necessary case "$OS" in Linux) TARGET_OS=unknown-linux-gnu ;; Darwin) TARGET_OS=apple-darwin ;; CYGWIN*|MINGW32*|MSYS*|MINGW*) TARGET_OS=pc-windows-msvc ;; *) echo "Unsupported OS: $OS"; exit 1 ;; esac case "$ARCH" in x86_64) TARGET_ARCH=x86_64 ;; aarch64|arm64) TARGET_ARCH=aarch64 ;; *) echo "Unsupported architecture: $ARCH"; exit 1 ;; esac TARGET="$TARGET_ARCH-$TARGET_OS" # Define the download URL for the latest release GITHUB_REPO="hg8496/rusty-buddy" API_URL="https://api.github.com/repos/$GITHUB_REPO/releases/latest" DOWNLOAD_URL=$(curl -s $API_URL \ | grep "browser_download_url.*rusty-buddy-$TARGET" \ | cut -d '"' -f 4) if [ -z "$DOWNLOAD_URL" ]; then echo "No suitable binary found for $TARGET." exit 1 fi echo "Downloading rusty-buddy binary for $TARGET..." curl -L "$DOWNLOAD_URL" -o "rusty-buddy" # Make the binary executable chmod +x rusty-buddy # Move it to the specified directory in the user's PATH mkdir -p "$BIN_DIR" mv rusty-buddy "$BIN_DIR/" echo "rusty-buddy installed successfully to $BIN_DIR" echo "Please ensure $BIN_DIR is in your PATH environment variable." # Add a helpful reminder to include the binary directory in PATH if [[ ":$PATH:" != *":$BIN_DIR:"* ]]; then echo "It seems $BIN_DIR is not in your PATH." echo "You can add it by adding the following line to your shell configuration file:" echo "export PATH=\"\$PATH:$BIN_DIR\"" fi # Install the zsh plugin if the option was specified if $INSTALL_PLUGIN; then PLUGIN_DIR="$HOME/.oh-my-zsh/custom/plugins/rusty-buddy" PLUGIN_URL="https://raw.githubusercontent.com/hg8496/rusty-buddy-zsh-plugin/refs/heads/main/rusty-buddy.plugin.zsh" mkdir -p "$PLUGIN_DIR" echo "Downloading zsh plugin for rusty-buddy..." curl -sL "$PLUGIN_URL" -o "$PLUGIN_DIR/rusty-buddy.plugin.zsh" echo "zsh plugin installed successfully!" echo "Add 'rusty-buddy' to your plugins in ~/.zshrc to activate it." fi