2026-05-11 22:04:11 +00:00
|
|
|
#!/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.
|
|
|
|
|
#
|
2026-05-30 18:35:40 +00:00
|
|
|
# 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 # reuse the cached binary
|
2026-05-14 15:00:57 +00:00
|
|
|
#
|
|
|
|
|
# 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.
|
2026-05-11 22:04:11 +00:00
|
|
|
#
|
2026-05-31 15:07:15 +00:00
|
|
|
# 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).
|
|
|
|
|
#
|
2026-05-11 22:04:11 +00:00
|
|
|
# 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
|
|
|
|
|
|
2026-05-30 18:35:40 +00:00
|
|
|
# Shared paths + helpers (log, ensure_binary, write_sample_wiki, seed_wiki).
|
|
|
|
|
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/_common.sh"
|
|
|
|
|
|
2026-05-11 22:04:11 +00:00
|
|
|
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" <<EOF
|
|
|
|
|
" start-vim.sh: generated minimal config for nuwiki development.
|
|
|
|
|
" Regenerated on every launch; edit start-vim.sh, not this file.
|
|
|
|
|
|
|
|
|
|
" Confine state to the dev cache so we never touch the user's real Vim
|
|
|
|
|
" install.
|
|
|
|
|
set viminfo='100,n$VIM_STATE/viminfo
|
|
|
|
|
let &directory = '$VIM_STATE/swap//'
|
|
|
|
|
let &backupdir = '$VIM_STATE/backup//'
|
|
|
|
|
let &undodir = '$VIM_STATE/undo//'
|
|
|
|
|
|
|
|
|
|
" Make Vim look for runtime paths in the dev cache.
|
|
|
|
|
set nocompatible
|
|
|
|
|
let &runtimepath = '$REPO_ROOT' . ',' . &runtimepath
|
|
|
|
|
let &runtimepath .= ',$VIM_LSP_DIR'
|
|
|
|
|
let &runtimepath .= ',$ASYNC_DIR'
|
|
|
|
|
|
|
|
|
|
let g:nuwiki_binary_path = '$REPO_ROOT/bin/nuwiki-ls'
|
|
|
|
|
let g:nuwiki_wiki_root = '$WIKI_DIR'
|
|
|
|
|
let g:nuwiki_file_extension = '.wiki'
|
|
|
|
|
let g:nuwiki_syntax = 'vimwiki'
|
|
|
|
|
let g:nuwiki_log_level = 'info'
|
|
|
|
|
|
|
|
|
|
filetype plugin indent on
|
|
|
|
|
syntax enable
|
|
|
|
|
set hidden
|
|
|
|
|
set termguicolors
|
|
|
|
|
set number
|
|
|
|
|
set signcolumn=yes
|
|
|
|
|
set noswapfile
|
|
|
|
|
set nobackup
|
|
|
|
|
set nowritebackup
|
|
|
|
|
let mapleader = ' '
|
|
|
|
|
|
|
|
|
|
" Auto-detect filetype for .wiki files (the plugin ships ftdetect, but
|
|
|
|
|
" --clean disables those — copy the rule here).
|
|
|
|
|
augroup NuwikiFtdetect
|
|
|
|
|
autocmd!
|
|
|
|
|
autocmd BufRead,BufNewFile *.wiki setfiletype vimwiki
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
" If vim-lsp is on the runtimepath, the plugin's autoload entry point
|
|
|
|
|
" registers the server automatically. Triggering it on FileType keeps
|
|
|
|
|
" the script's responsibility minimal.
|
|
|
|
|
augroup NuwikiStart
|
|
|
|
|
autocmd!
|
|
|
|
|
autocmd FileType vimwiki call nuwiki#lsp#start()
|
|
|
|
|
augroup END
|
|
|
|
|
|
2026-05-12 01:15:53 +00:00
|
|
|
" Status messages go to :messages so they don't trigger "Press ENTER".
|
|
|
|
|
echomsg '[nuwiki-dev] ready — wiki root: $WIKI_DIR'
|
|
|
|
|
echomsg '[nuwiki-dev] :LspStatus for diagnostics, :messages for log'
|
2026-05-11 22:04:11 +00:00
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main() {
|
|
|
|
|
ensure_binary
|
|
|
|
|
ensure_vim_lsp
|
|
|
|
|
seed_wiki
|
|
|
|
|
write_vimrc
|
2026-05-31 15:07:15 +00:00
|
|
|
reset_dirs "$VIM_STATE"
|
2026-05-11 22:04:11 +00:00
|
|
|
mkdir -p "$VIM_STATE/swap" "$VIM_STATE/backup" "$VIM_STATE/undo"
|
|
|
|
|
|
|
|
|
|
log "launching: vim --clean -u $VIMRC"
|
|
|
|
|
if [[ $# -gt 0 ]]; then
|
|
|
|
|
exec vim --clean -u "$VIMRC" "$@"
|
|
|
|
|
else
|
|
|
|
|
exec vim --clean -u "$VIMRC" "$WIKI_DIR/index.wiki"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main "$@"
|