#!/usr/bin/env bash # shellcheck disable=SC2086 # Installs superfile (terminal file manager) — https://github.com/yorukot/superfile # Also installs JetBrains Mono Nerd Font (required for proper icon display). # # Mac/Linux: Uses the official superfile installer # Windows: See install-superfile.ps1 (winget) # # Supported platforms: # macOS : Apple Silicon (arm64), Intel (x86_64) # Linux : x86_64, aarch64/arm64 set -euo pipefail # ──────────────────────────────────────────── # Utility functions (all stderr output) # ──────────────────────────────────────────── info() { echo "[INFO] $*" >&2; } warn() { echo "[WARN] $*" >&2; } error() { echo "[ERROR] $*" >&2 exit 1 } success() { echo "[OK] $*" >&2; } # ──────────────────────────────────────────── # Ensure Homebrew is available on macOS # ──────────────────────────────────────────── ensure_brew() { if command -v brew &>/dev/null; then return 0 fi info "Homebrew is not installed. Installing Homebrew..." /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" if [ -d /opt/homebrew/bin ]; then export PATH="/opt/homebrew/bin:$PATH" fi if [ -d /usr/local/bin ]; then export PATH="/usr/local/bin:$PATH" fi command -v brew &>/dev/null || error "Homebrew installation failed. Install it manually: https://brew.sh/" success "Homebrew installed" } # ──────────────────────────────────────────── # Check required commands # ──────────────────────────────────────────── for cmd in curl; do command -v "$cmd" &>/dev/null || error "'$cmd' command is required." done # ──────────────────────────────────────────── # Step 1: Install superfile # ──────────────────────────────────────────── info "Installing superfile (terminal file manager)..." if command -v spf &>/dev/null; then CURRENT_VER="$(spf --version 2>/dev/null || echo 'unknown')" info "superfile is already installed ($CURRENT_VER). Skipping installation." else bash -c "$(curl -sLo- https://superfile.dev/install.sh)" success "superfile installed via official installer" fi # Verify spf is available if command -v spf &>/dev/null; then success "superfile is available: $(command -v spf)" else warn "superfile was not found in PATH after installation. You may need to open a new terminal." fi # ──────────────────────────────────────────── # Step 2: Install JetBrains Mono Nerd Font # ──────────────────────────────────────────── info "Installing JetBrains Mono Nerd Font (required for icon display)..." OS="$(uname -s)" case "$OS" in Darwin) brew install --cask font-jetbrains-mono-nerd-font success "JetBrains Mono Nerd Font installed via Homebrew" ;; Linux) FONT_DIR="${HOME}/.local/share/fonts" FONT_NAME="JetBrainsMonoNerdFont" FONT_ZIP="JetBrainsMono.tar.xz" FONT_URL="https://github.com/ryanoasis/nerd-fonts/releases/latest/download/${FONT_ZIP}" # Check if font is already installed if fc-list 2>/dev/null | grep -qi "$FONT_NAME"; then info "JetBrains Mono Nerd Font is already installed. Skipping." else TMPDIR="$(mktemp -d)" trap '[ -d "${TMPDIR:-}" ] && rm -rf "$TMPDIR"' EXIT info "Downloading: $FONT_URL" curl -fsSL --progress-bar -o "${TMPDIR}/${FONT_ZIP}" "$FONT_URL" || warn "Failed to download Nerd Font. Icons may not display correctly." if [ -f "${TMPDIR}/${FONT_ZIP}" ]; then mkdir -p "$FONT_DIR" tar -xf "${TMPDIR}/${FONT_ZIP}" -C "$FONT_DIR" 2>/dev/null || warn "Failed to extract font archive." # Rebuild font cache if command -v fc-cache &>/dev/null; then fc-cache -f "$FONT_DIR" 2>/dev/null fi success "JetBrains Mono Nerd Font installed to $FONT_DIR" fi fi ;; *) warn "JetBrains Mono Nerd Font auto-install is not supported on $OS." warn "Install it manually from: https://github.com/ryanoasis/nerd-fonts" ;; esac # ──────────────────────────────────────────── # Step 3: Post-install notes # ──────────────────────────────────────────── info "" info "==================================================" success "superfile installation complete!" info "==================================================" info "" info "Getting started:" info " spf - Start superfile file manager" info " spf --help - Show help" info "" info "Note: The command name is 'spf', not 'superfile'." info "" info "Key bindings (vim-style):" info " h/j/k/l - Left/Down/Up/Right" info " Enter - Open directory / file" info " y - Yank (copy)" info " d - Delete" info " r - Rename" info " / - Search" info " Tab - Switch panel"