#!/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. # # Usage: ./start-vim.sh [extra args...] # ./start-vim.sh # open the scratch wiki's index # ./start-vim.sh path/to/note.wiki # open a specific file # NUWIKI_DEV_WIKI=/tmp/foo ./start-vim.sh # NUWIKI_DEV_NO_LSP=1 ./start-vim.sh # skip vim-lsp setup # NUWIKI_DEV_SKIP_BUILD=1 ./start-vim.sh # reuse the cached binary # # The release binary is rebuilt on every launch so source changes # always reach the running LSP. `cargo build --release` is incremental, # so this is a fast no-op when nothing changed. Set # NUWIKI_DEV_SKIP_BUILD=1 to skip the build step entirely. # # 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 REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" DEV_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/nuwiki-dev" WIKI_DIR="${NUWIKI_DEV_WIKI:-$DEV_DIR/wiki}" VIMRC="$DEV_DIR/vimrc" VIM_STATE="$DEV_DIR/vim-state" VIM_LSP_DIR="$DEV_DIR/vim-lsp" ASYNC_DIR="$DEV_DIR/async.vim" log() { printf '\033[1;34m[nuwiki-dev]\033[0m %s\n' "$*"; } ensure_binary() { local bin="$REPO_ROOT/bin/nuwiki-ls" local built="$REPO_ROOT/target/release/nuwiki-ls" if [[ "${NUWIKI_DEV_SKIP_BUILD:-0}" == "1" ]]; then if [[ ! -x "$bin" ]]; then log "NUWIKI_DEV_SKIP_BUILD=1 but $bin is missing — building anyway" else log "NUWIKI_DEV_SKIP_BUILD=1 — using existing $bin" return fi fi log "building nuwiki-ls (release)…" cargo build --release -p nuwiki-ls --manifest-path "$REPO_ROOT/Cargo.toml" mkdir -p "$REPO_ROOT/bin" ln -sf "$built" "$bin" log "binary ready: $bin (built $(date -r "$built" '+%Y-%m-%d %H:%M:%S'))" } 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 } seed_wiki() { mkdir -p "$WIKI_DIR" "$WIKI_DIR/diary" if [[ ! -f "$WIKI_DIR/index.wiki" ]]; then cat > "$WIKI_DIR/index.wiki" <<'EOF' = Welcome to nuwiki = This is a scratch wiki created by start-vim.sh. Edit, run commands, or jump to the linked pages to test the plugin. == Smoke test == - [[Notes]] - [[diary/]] - [ ] Toggle me with :VimwikiToggleListItem - [ ] Inspect the LSP via :LspStatus == Commands to try == - :VimwikiTOC - :VimwikiGenerateLinks - :VimwikiCheckLinks - :VimwikiMakeDiaryNote == Tags == :smoke-test:sandbox: EOF fi if [[ ! -f "$WIKI_DIR/Notes.wiki" ]]; then cat > "$WIKI_DIR/Notes.wiki" <<'EOF' = Notes = A second page so [[index]] has somewhere to point. == Section one == Anchor target for cross-page link follows. EOF fi } write_vimrc() { mkdir -p "$DEV_DIR" cat > "$VIMRC" <