This commit is contained in:
2026-01-16 12:03:49 +00:00
parent bdc74a3ef6
commit 543c868789

View File

@@ -1,104 +1,117 @@
#!/bin/bash
set -euo pipefail
# Parse flags like: ./install.sh macos=1 linux=1
for arg in "$@"; do declare "$arg"='1'; done
for arg in "$@"; do
# allows: ./install.sh macos (sets $macos=1)
declare "${arg}=1"
done
# Determine OS if not explicitly provided
if [[ "$(uname -s)" == "Darwin" ]]; then
macos="${macos:-1}"
linux="${linux:-}"
if [[ -n "${macos:-}" ]]; then
linux=""
else
linux="${linux:-1}"
macos="${macos:-}"
linux=1
fi
need_cmd() { command -v "$1" >/dev/null 2>&1; }
install_neovim() {
if command -v nvim >/dev/null 2>&1; then
return 0
fi
if [[ -z "${linux:-}" ]]; then
# macOS
if command -v brew >/dev/null 2>&1; then
brew install neovim
return 0
fi
echo "Neovim not found and Homebrew is not installed. Install Homebrew or install Neovim manually." >&2
return 1
fi
# Linux (curl-based install, NOT AppImage): download official tarball and install into ~/.local
if ! command -v curl >/dev/null 2>&1; then
echo "curl is required to install Neovim on Linux." >&2
return 1
fi
install_neovim_linux() {
# Install latest stable Neovim from GitHub releases (official tarball)
local arch tmp url
arch="$(uname -m)"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' RETURN
case "$arch" in
x86_64|amd64) url="https://github.com/neovim/neovim/releases/latest/download/nvim-linux-x86_64.tar.gz" ;;
aarch64|arm64) url="https://github.com/neovim/neovim/releases/latest/download/nvim-linux-arm64.tar.gz" ;;
x86_64) nvim_arch="linux-x86_64" ;;
aarch64|arm64) nvim_arch="linux-arm64" ;;
*)
echo "Unsupported architecture: $arch" >&2
echo "Unsupported architecture for tarball install: $arch" >&2
return 1
;;
esac
# -f: fail on HTTP errors, -L: follow redirects, -S: show errors
curl -fL --retry 3 --retry-delay 1 -o "$tmp/nvim.tar.gz" "$url"
base="$HOME/.local"
mkdir -p "$base/bin"
# quick sanity check (avoids "not in gzip format")
if ! tar -tzf "$tmp/nvim.tar.gz" >/dev/null 2>&1; then
echo "Downloaded file is not a valid gzip tarball: $url" >&2
echo "First bytes:" >&2
head -c 200 "$tmp/nvim.tar.gz" | sed -e 's/[^[:print:]\t]/./g' >&2
return 1
fi
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
sudo rm -rf /opt/nvim
sudo mkdir -p /opt
sudo tar -C /opt -xzf "$tmp/nvim.tar.gz"
# Stable release tarball (change v* URL if you want nightly)
url="https://github.com/neovim/neovim/releases/latest/download/nvim-${nvim_arch}.tar.gz"
curl -fsSL "$url" -o "$tmpdir/nvim.tar.gz"
# tarball extracts to /opt/nvim-linux64 or /opt/nvim-linuxarm64
local extracted
extracted="$(tar -tzf "$tmp/nvim.tar.gz" | head -n1 | cut -d/ -f1)"
sudo mv "/opt/$extracted" /opt/nvim
tar -xzf "$tmpdir/nvim.tar.gz" -C "$tmpdir"
sudo mkdir -p /usr/local/bin
sudo ln -sf /opt/nvim/bin/nvim /usr/local/bin/nvim
}
# The extracted folder is named nvim-linux-<arch>
src_dir="$tmpdir/nvim-${nvim_arch}"
install_neovim_macos() {
if need_cmd brew; then
brew install neovim
else
echo "Homebrew not found. Install brew or neovim manually." >&2
return 1
# Install by replacing ~/.local/nvim
rm -rf "$base/nvim"
mv "$src_dir" "$base/nvim"
# Symlink binary into ~/.local/bin
ln -sf "$base/nvim/bin/nvim" "$base/bin/nvim"
if ! printf '%s' "${PATH:-}" | tr ':' '\n' | grep -qx "$base/bin"; then
echo "Installed nvim to $base/bin/nvim. Ensure $base/bin is in your PATH." >&2
fi
}
ensure_neovim() {
if need_cmd nvim; then
return 0
fi
mkdir -p "$HOME/.config"
echo "neovim not found; installing..."
if [[ -n "${linux:-}" ]]; then
install_neovim_linux
else
install_neovim_macos
fi
}
# --- Ensure nvim installed before linking config ---
ensure_neovim
# install neovim if missing
install_neovim
# install neovim config
if [ ! -d "$HOME/.config/nvim" ]; then
mkdir -p "$HOME/.config"
ln -s "$HOME/dotfiles/nvim" "$HOME/.config/nvim" || :
fi
# install starship config
mkdir -p "$HOME/.config"
ln -s "$HOME/dotfiles/starship.toml" "$HOME/.config/starship.toml" || :
if [ ! -n "${linux:-}" ]; then
# macos-only configs
ln -s "$HOME/dotfiles/aerospace.toml" "$HOME/.aerospace.toml" || :
for d in sketchybar borders neovide ghostty; do
[ -d "$HOME/.config/$d" ] || ln -s "$HOME/dotfiles/$d" "$HOME/.config/$d" || :
done
if [ ! -d "$HOME/.config/sketchybar" ]; then
ln -s "$HOME/dotfiles/sketchybar" "$HOME/.config/sketchybar" || :
fi
if [ ! -d "$HOME/.config/borders" ]; then
ln -s "$HOME/dotfiles/borders" "$HOME/.config/borders" || :
fi
if [ ! -d "$HOME/.config/neovide" ]; then
ln -s "$HOME/dotfiles/neovide" "$HOME/.config/neovide" || :
fi
if [ ! -d "$HOME/.config/ghostty" ]; then
ln -s "$HOME/dotfiles/ghostty" "$HOME/.config/ghostty" || :
fi
else
for d in sway waybar rofi dunst; do
[ -d "$HOME/.config/$d" ] || ln -s "$HOME/dotfiles/$d" "$HOME/.config/$d" || :
done
# linux-only configs
if [ ! -d "$HOME/.config/sway" ]; then
ln -s "$HOME/dotfiles/sway" "$HOME/.config/sway" || :
fi
if [ ! -d "$HOME/.config/waybar" ]; then
ln -s "$HOME/dotfiles/waybar" "$HOME/.config/waybar" || :
fi
if [ ! -d "$HOME/.config/rofi" ]; then
ln -s "$HOME/dotfiles/rofi" "$HOME/.config/rofi" || :
fi
if [ ! -d "$HOME/.config/dunst" ]; then
ln -s "$HOME/dotfiles/dunst" "$HOME/.config/dunst" || :
fi
fi