2026-05-11 22:04:11 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
#
|
|
|
|
|
# start-nvim.sh — launch Neovim with a minimal config that loads nuwiki.
|
|
|
|
|
#
|
|
|
|
|
# Builds the language server (release mode), symlinks it into `bin/` so
|
|
|
|
|
# the plugin's default install path resolves, then spawns Neovim with
|
|
|
|
|
# `--clean` and a generated `init.lua` that:
|
|
|
|
|
# * adds this repo to `runtimepath`
|
|
|
|
|
# * configures wiki_root to a scratch directory under
|
|
|
|
|
# $XDG_CACHE_HOME/nuwiki-dev/wiki
|
|
|
|
|
# * calls `require('nuwiki').setup({...})`
|
|
|
|
|
#
|
|
|
|
|
# Usage: ./start-nvim.sh [extra args...]
|
|
|
|
|
# ./start-nvim.sh # open the scratch wiki's index
|
|
|
|
|
# ./start-nvim.sh path/to/note.wiki # open a specific file
|
|
|
|
|
# NUWIKI_DEV_WIKI=/tmp/foo ./start-nvim.sh
|
2026-05-14 15:00:57 +00:00
|
|
|
# NUWIKI_DEV_SKIP_BUILD=1 ./start-nvim.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.
|
2026-05-11 22:04:11 +00:00
|
|
|
#
|
|
|
|
|
# Tested with Neovim 0.10+. State (cache/data/config) lives under
|
|
|
|
|
# $XDG_CACHE_HOME/nuwiki-dev/ so your real Neovim 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}"
|
|
|
|
|
INIT_FILE="$DEV_DIR/init.lua"
|
|
|
|
|
STATE_DIR="$DEV_DIR/nvim-state"
|
|
|
|
|
DATA_DIR="$DEV_DIR/nvim-data"
|
|
|
|
|
CONFIG_DIR="$DEV_DIR/nvim-config"
|
|
|
|
|
|
|
|
|
|
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"
|
2026-05-14 15:00:57 +00:00
|
|
|
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
|
2026-05-11 22:04:11 +00:00
|
|
|
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"
|
2026-05-14 15:00:57 +00:00
|
|
|
log "binary ready: $bin (built $(date -r "$built" '+%Y-%m-%d %H:%M:%S'))"
|
2026-05-11 22:04:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-nvim.sh. Edit, run commands,
|
|
|
|
|
or jump to the linked pages to test the plugin.
|
|
|
|
|
|
|
|
|
|
== Smoke test ==
|
|
|
|
|
|
|
|
|
|
- [[Notes]]
|
|
|
|
|
- [[diary/]]
|
|
|
|
|
- [ ] Toggle me with <C-Space>
|
|
|
|
|
- [ ] Or with :VimwikiToggleListItem
|
|
|
|
|
|
|
|
|
|
== Commands to try ==
|
|
|
|
|
|
|
|
|
|
- :VimwikiTOC
|
|
|
|
|
- :VimwikiGenerateLinks
|
|
|
|
|
- :VimwikiCheckLinks
|
|
|
|
|
- :VimwikiMakeDiaryNote
|
|
|
|
|
- :Vimwiki2HTMLBrowse
|
|
|
|
|
|
|
|
|
|
== Tags ==
|
|
|
|
|
|
|
|
|
|
:smoke-test:sandbox:
|
|
|
|
|
|
|
|
|
|
== Links ==
|
|
|
|
|
|
|
|
|
|
* [[Notes]]
|
|
|
|
|
* [[Notes#section-one]]
|
|
|
|
|
* https://example.com
|
|
|
|
|
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 :checkhealth-style smoke tests.
|
|
|
|
|
EOF
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
write_init() {
|
|
|
|
|
mkdir -p "$DEV_DIR"
|
|
|
|
|
cat > "$INIT_FILE" <<EOF
|
|
|
|
|
-- start-nvim.sh: generated minimal config for nuwiki development.
|
|
|
|
|
-- Regenerated on every launch; edit start-nvim.sh, not this file.
|
|
|
|
|
|
|
|
|
|
-- Confine state to the dev cache so we never touch the user's real
|
|
|
|
|
-- Neovim install.
|
|
|
|
|
vim.env.XDG_STATE_HOME = '$STATE_DIR'
|
|
|
|
|
vim.env.XDG_DATA_HOME = '$DATA_DIR'
|
|
|
|
|
vim.env.XDG_CONFIG_HOME = '$CONFIG_DIR'
|
|
|
|
|
|
|
|
|
|
vim.opt.runtimepath:prepend('$REPO_ROOT')
|
|
|
|
|
|
|
|
|
|
vim.g.nuwiki_binary_path = '$REPO_ROOT/bin/nuwiki-ls'
|
|
|
|
|
|
|
|
|
|
-- Friendly defaults for an interactive smoke test.
|
|
|
|
|
vim.opt.number = true
|
|
|
|
|
vim.opt.signcolumn = 'yes'
|
|
|
|
|
vim.opt.termguicolors = true
|
|
|
|
|
vim.opt.swapfile = false
|
|
|
|
|
vim.opt.writebackup = false
|
|
|
|
|
vim.opt.undofile = false
|
|
|
|
|
vim.g.mapleader = ' '
|
|
|
|
|
|
|
|
|
|
require('nuwiki').setup({
|
|
|
|
|
wiki_root = '$WIKI_DIR',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
-- Surface log lines (the LSP logs via window/logMessage). Without this
|
|
|
|
|
-- they're swallowed; with it they land in :messages.
|
|
|
|
|
vim.lsp.set_log_level('info')
|
|
|
|
|
|
|
|
|
|
print('[nuwiki-dev] ready — wiki root: $WIKI_DIR')
|
|
|
|
|
print('[nuwiki-dev] :LspInfo to inspect, :checkhealth nuwiki for diagnostics')
|
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main() {
|
|
|
|
|
ensure_binary
|
|
|
|
|
seed_wiki
|
|
|
|
|
write_init
|
|
|
|
|
mkdir -p "$STATE_DIR" "$DATA_DIR" "$CONFIG_DIR"
|
|
|
|
|
|
|
|
|
|
log "launching: nvim --clean -u $INIT_FILE"
|
|
|
|
|
if [[ $# -gt 0 ]]; then
|
|
|
|
|
exec nvim --clean -u "$INIT_FILE" "$@"
|
|
|
|
|
else
|
|
|
|
|
exec nvim --clean -u "$INIT_FILE" "$WIKI_DIR/index.wiki"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main "$@"
|