Move dev launcher scripts into scripts/ to declutter root
CI / cargo fmt --check (push) Successful in 37s
CI / cargo clippy (push) Successful in 35s
CI / cargo test (push) Successful in 32s
CI / cargo fmt --check (pull_request) Successful in 29s
CI / cargo clippy (pull_request) Successful in 46s
CI / cargo test (pull_request) Successful in 52s
CI / editor keymaps (push) Successful in 1m36s
CI / editor keymaps (pull_request) Successful in 1m21s

Relocate start-nvim.sh, start-vim.sh and test-personal-wiki.sh from the
repo root into scripts/, alongside the existing test harnesses. Each
script now derives REPO_ROOT one level up, test-personal-wiki.sh execs
the moved start-vim.sh, and the README + usage comments point at the new
paths.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-30 14:09:06 -03:00
parent 21ac9deb23
commit 9ec1adb3e7
4 changed files with 22 additions and 22 deletions
+158
View File
@@ -0,0 +1,158 @@
#!/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: ./scripts/start-nvim.sh [extra args...]
# ./scripts/start-nvim.sh # open the scratch wiki's index
# ./scripts/start-nvim.sh path/to/note.wiki # open a specific file
# NUWIKI_DEV_WIKI=/tmp/foo ./scripts/start-nvim.sh
# NUWIKI_DEV_SKIP_BUILD=1 ./scripts/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.
#
# 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"
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'))"
}
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 "$@"
+197
View File
@@ -0,0 +1,197 @@
#!/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: ./scripts/start-vim.sh [extra args...]
# ./scripts/start-vim.sh # open the scratch wiki's index
# ./scripts/start-vim.sh path/to/note.wiki # open a specific file
# NUWIKI_DEV_WIKI=/tmp/foo ./scripts/start-vim.sh
# NUWIKI_DEV_NO_LSP=1 ./scripts/start-vim.sh # skip vim-lsp setup
# NUWIKI_DEV_NO_SEED=1 ./scripts/start-vim.sh # use WIKI_DIR as-is (no scratch seeding)
# NUWIKI_DEV_SKIP_BUILD=1 ./scripts/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() {
if [[ "${NUWIKI_DEV_NO_SEED:-0}" == "1" ]]; then
log "NUWIKI_DEV_NO_SEED=1 — skipping wiki seed (using $WIKI_DIR as-is)"
return
fi
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" <<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
" 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'
EOF
}
main() {
ensure_binary
ensure_vim_lsp
seed_wiki
write_vimrc
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 "$@"
+34
View File
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
#
# test-personal-wiki.sh — open the user's real personal wiki via start-vim.sh.
#
# Reuses start-vim.sh's plumbing (binary build, vim-lsp clone, viminfo
# under the dev cache) but points the wiki root at ~/.vimwiki/personal_wiki
# and disables seed_wiki so we don't drop a scratch `Notes.wiki` into your
# real notes.
#
# Useful when reproducing a user-reported bug against actual content rather
# than the seeded smoke-test wiki. State (viminfo/sessions) still lives
# under $XDG_CACHE_HOME/nuwiki-dev/ so your real Vim install stays untouched.
#
# Usage:
# ./scripts/test-personal-wiki.sh # open index.wiki
# ./scripts/test-personal-wiki.sh path/to/note.wiki # open a specific file
# NUWIKI_PERSONAL_WIKI=/other/path ./scripts/test-personal-wiki.sh
# NUWIKI_DEV_SKIP_BUILD=1 ./scripts/test-personal-wiki.sh # reuse the cached binary
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
WIKI_DIR="${NUWIKI_PERSONAL_WIKI:-$HOME/.vimwiki/personal_wiki}"
if [[ ! -d "$WIKI_DIR" ]]; then
echo "test-personal-wiki: $WIKI_DIR does not exist" >&2
echo "set NUWIKI_PERSONAL_WIKI to point at your wiki, or create the default path" >&2
exit 1
fi
export NUWIKI_DEV_WIKI="$WIKI_DIR"
export NUWIKI_DEV_NO_SEED=1
exec "$REPO_ROOT/scripts/start-vim.sh" "$@"