#!/usr/bin/env bash # # start-vim.sh — launch Vim with a minimal config that loads nuwiki. # # The plugin's Vim path (autoload/nuwiki/lsp.vim) prefers `vim-lsp` and # falls back to `coc.nvim`. This script clones vim-lsp + async.vim into # the dev cache on first run so the LSP integration is exercisable # without polluting your real Vim install. # # The plugin's install() downloads a pre-built release of nuwiki-ls for # your platform from the nuwiki-rs repository. On first launch a missing # binary is auto-downloaded via the bundled Vim script; set # NUWIKI_DEV_SKIP_BUILD=1 to skip the download entirely. # # Usage: ./development/start-vim.sh [extra args...] # ./development/start-vim.sh # open the scratch wiki's index # ./development/start-vim.sh path/to/note.wiki # open a specific file # NUWIKI_DEV_WIKI=/tmp/foo ./development/start-vim.sh # NUWIKI_DEV_NO_LSP=1 ./development/start-vim.sh # skip vim-lsp setup # NUWIKI_DEV_NO_SEED=1 ./development/start-vim.sh # use WIKI_DIR as-is (no scratch seeding) # NUWIKI_DEV_SKIP_BUILD=1 ./development/start-vim.sh # skip the download step # # Each launch starts clean: the scratch wiki is reseeded from a pristine # copy and the editor state (viminfo/swap/undo) is wiped, so stale edits # never carry over. The cached vim-lsp/async.vim clones are kept. A wiki you # point at with NUWIKI_DEV_WIKI is never wiped (seeded only if empty). # # Tested with Vim 9.1+. State (viminfo/sessions) lives under # $XDG_CACHE_HOME/nuwiki-dev/ so your real Vim install stays untouched. set -euo pipefail # Shared paths + helpers (log, ensure_binary, write_sample_wiki, seed_wiki). source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/_common.sh" VIMRC="$DEV_DIR/vimrc" VIM_STATE="$DEV_DIR/vim-state" VIM_LSP_DIR="$DEV_DIR/vim-lsp" ASYNC_DIR="$DEV_DIR/async.vim" clone_if_missing() { local repo_url="$1" local dest="$2" if [[ -d "$dest/.git" ]]; then return fi if ! command -v git >/dev/null 2>&1; then log "git not found — skipping $repo_url" return 1 fi log "cloning $repo_url → $dest" git clone --depth 1 "$repo_url" "$dest" >/dev/null 2>&1 } ensure_vim_lsp() { if [[ "${NUWIKI_DEV_NO_LSP:-0}" == "1" ]]; then log "NUWIKI_DEV_NO_LSP=1 — skipping vim-lsp setup" return fi mkdir -p "$DEV_DIR" clone_if_missing https://github.com/prabirshrestha/vim-lsp.git "$VIM_LSP_DIR" || true clone_if_missing https://github.com/prabirshrestha/async.vim.git "$ASYNC_DIR" || true } write_vimrc() { mkdir -p "$DEV_DIR" cat > "$VIMRC" <