From 6eefc4d7422e8efc5410709f28ea5b710ee6a7e0 Mon Sep 17 00:00:00 2001 From: xs Date: Tue, 3 Nov 2026 14:52:54 +0800 Subject: setup.sh: idempotent vimlsp section (vimrc, vim-plug plugins, fzf, rust-analyzer, uv, ruff, ty); README --- setup.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'setup.sh') diff --git a/setup.sh b/setup.sh index f0cf83b..d33733d 100755 --- a/setup.sh +++ b/setup.sh @@ -3,6 +3,56 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd "$SCRIPT_DIR" || exit +# Vim LSP setup (idempotent; each step = action + check, first failure stops). +# Run only this part: ./setup.sh vimlsp +vimlsp() { + set -e + ok() { echo "ok $*"; } + die() { echo "FAIL $*" >&2; exit 1; } + VIMRC_SRC="$SCRIPT_DIR/core/vimrc" + export PATH="$HOME/.cargo/bin:$HOME/.local/bin:$PATH" + + # vimrc: plain copy into ~/.vimrc, back up a different existing one + if [ -f ~/.vimrc ] && ! cmp -s "$VIMRC_SRC" ~/.vimrc; then + cp ~/.vimrc ~/.vimrc.bak-"$(date +%F)"; ok "backed up ~/.vimrc to ~/.vimrc.bak-$(date +%F)" + fi + cmp -s "$VIMRC_SRC" ~/.vimrc || cp "$VIMRC_SRC" ~/.vimrc + { cmp -s "$VIMRC_SRC" ~/.vimrc && [ ! -L ~/.vimrc ]; } || die "~/.vimrc"; ok "~/.vimrc matches core/vimrc" + + # vim-plug + [ -f ~/.vim/autoload/plug.vim ] || curl -fsSLo ~/.vim/autoload/plug.vim --create-dirs \ + https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim + grep -q 'plug#begin' ~/.vim/autoload/plug.vim || die "plug.vim"; ok "vim-plug ~/.vim/autoload/plug.vim" + + # plugins: every Plug line of the vimrc, plain depth-1 git clone into ~/.vim/plugged + for repo in $(sed -n "s/^Plug '\([^']*\)'.*/\1/p" "$VIMRC_SRC"); do + d=~/.vim/plugged/${repo#*/} + [ -d "$d/.git" ] || git clone -q --depth 1 "https://github.com/$repo" "$d" + git -C "$d" rev-parse --verify -q HEAD > /dev/null || die "plugin $repo"; ok "plugin $repo" + done + [ -x ~/.vim/plugged/fzf/bin/fzf ] || ~/.vim/plugged/fzf/install --bin > /dev/null 2>&1 + ~/.vim/plugged/fzf/bin/fzf --version > /dev/null || die "fzf binary"; ok "fzf binary" + + # rust-analyzer (Rust itself comes from core/packages/install_rust.sh) + if rustup which rustc > /dev/null 2>&1; then + rustup component list --installed | grep -q '^rust-analyzer' || rustup component add rust-analyzer + rustup component list --installed | grep -q '^rust-src' || rustup component add rust-src + rust-analyzer --version > /dev/null || die "rust-analyzer"; ok "rust-analyzer $(rust-analyzer --version)" + else + echo "skip rust-analyzer: no rustup toolchain (run core/packages/install_rust.sh first)" + fi + + # uv, ruff, ty + command -v uv > /dev/null || curl -LsSf https://astral.sh/uv/install.sh | UV_NO_MODIFY_PATH=1 sh + uv --version > /dev/null || die "uv"; ok "$(uv --version)" + for t in ruff ty; do + command -v $t > /dev/null || uv tool install $t + $t --version > /dev/null || die "$t"; ok "$($t --version)" + done + echo "vimlsp done" +} +[ "$1" = vimlsp ] && { vimlsp; exit $?; } + # Shell appearance (only append if not already present) grep -q 'di=38;5;135' /etc/bashrc || sudo tee -a /etc/bashrc > /dev/null << 'EOF' LS_COLORS=$LS_COLORS:'di=38;5;135:ex=00;32:' ; export LS_COLORS @@ -19,3 +69,6 @@ sudo bash ./core/ssh.sh || { echo "Failed to configure SSH"; exit 1 sudo bash ./core/install-packages.sh || { echo "Failed to install packages"; exit 1; } sudo bash ./core/vim.sh || { echo "Failed to configure Vim"; exit 1; } sudo bash ./core/tmux.sh || { echo "Failed to configure Tmux"; exit 1; } + +# Vim LSP setup for the invoking user +( vimlsp ) || { echo "Failed to set up vim LSP"; exit 1; } -- cgit