From 7f3a48414bb4783fcd577c66e90c3134c8ad407f Mon Sep 17 00:00:00 2001 From: samuido Date: Thu, 5 Nov 2026 00:25:20 +0900 Subject: [PATCH 1/5] feat(editor): add Unix entry points and platform-aware linking Vim/Neovim configuration only existed as Windows-layout entry points, so on macOS and WSL no editor loaded home/vimfiles/shared/base.vim (the Onishi keymap) at all. - home/.vimrc: POSIX Vim entry point. Sources $VIMRUNTIME/vimrc_example.vim (portable template, restores defaults.vim now that a user vimrc exists) then the shared base.vim, mirroring the Windows _vimrc minus the Windows-only diffexpr/MyDiff block (dead code: Vim 9 ships 'internal' in 'diffopt' on every platform). - home/vimfiles/nvim/init.lua: the canonical 281-line Neovim config, moved unchanged from home/AppData/Local/nvim/init.lua. Both Neovim entry points (home/.config/nvim/init.lua for POSIX, home/AppData/Local/nvim/init.lua for Windows) are byte-identical thin loaders of it, so the config is never duplicated per OS. - script/link + script/check: skip home/AppData/ on POSIX with a printed reason. Skipped sources are never linked and never removed; a pre-existing AppData tree stays untouched and stops being reported as drift. - script/link.ps1: skip home/.vimrc and home/.config/nvim/ on Windows (Neovim reads %LOCALAPPDATA%\nvim\init.lua there) with the same printed-reason style, plus a prefix rule for future files in that tree. - script/test and script/link.windows.test.ts cover both rules. --- README.md | 10 +- home/.config/nvim/init.lua | 11 ++ home/.vimrc | 22 +++ home/AppData/Local/nvim/init.lua | 286 +------------------------------ home/vimfiles/nvim/init.lua | 281 ++++++++++++++++++++++++++++++ home/vimfiles/shared/base.vim | 6 +- script/check | 12 ++ script/link | 20 +++ script/link.ps1 | 16 ++ script/link.windows.test.ts | 15 +- script/test | 55 ++++++ 11 files changed, 449 insertions(+), 285 deletions(-) create mode 100644 home/.config/nvim/init.lua create mode 100644 home/.vimrc create mode 100644 home/vimfiles/nvim/init.lua diff --git a/README.md b/README.md index 15cfe41..309ca0e 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,7 @@ git submodule status --recursive - Keep only configuration that I actually use or need to reproduce. - `home/` mirrors `$HOME`; managed files are linked individually into the real home directory. An entry may be a regular file or a symlink into an agent submodule. +- Platform-specific entries are skipped by name (`AppData/` on POSIX, `.vimrc` and `.config/nvim/` on Windows), with the reason printed. A skipped source is never linked and never removed: existing user state is left exactly as it is. - Linking is idempotent and non-destructive. `script/link` never overwrites unmanaged targets; `script/bootstrap` only adopts known legacy Git targets after preserving backups and migrating user-owned state. - Secret values are not Git state. The self-hosted Infisical instance at `https://secrets.rebuildup.dev` is the canonical secret source of truth. - Prefer process-scoped `infisical run` injection over global exports or persistent plaintext `.env` files. @@ -247,11 +248,14 @@ The current common Git baseline includes: - global ignore via `~/.config/git/ignore` - machine/user-local `~/.gitconfig.local` -The editor baseline is shared between Vim and Neovim: +The editor baseline is shared between Vim and Neovim. Each OS has only a thin +entry point; the configuration itself lives once under `home/vimfiles/`: -- `~/vimfiles/shared/base.vim` — the single source of truth for both editors (encoding, `~/.cache/vim` backup/swap/undo, display, folding, search, indent, statusline, `list`, window/tab/normal/insert/visual mappings, transparent background). Sourced by Vim's `_vimrc` and by Neovim's `init.lua`. +- `~/vimfiles/shared/base.vim` — the single source of truth for both editors (encoding, `~/.cache/vim` backup/swap/undo, display, folding, search, indent, statusline, `list`, window/tab/normal/insert/visual mappings, transparent background). - `~/vimfiles/keymap/onishi.vim` — 大西配列 key placement; sourced last from `base.vim` so it overrides the defaults above. -- `%LOCALAPPDATA%\Programs\Vim\_vimrc` and `%LOCALAPPDATA%\nvim\` (Neovim config, lockfiles, `scripts/`, `snippets/`) mirror their real Windows locations under `home/AppData/Local/` so neither editor needs an environment variable to find its config. +- `~/vimfiles/nvim/init.lua` — the canonical Neovim config (plugins, keymaps, LSP). The two Neovim entry points below are byte-identical thin loaders of this file, so the lua config is never maintained per OS. +- Entry points: `home/.vimrc` → `~/.vimrc` and `home/.config/nvim/init.lua` → `~/.config/nvim/init.lua` on macOS/WSL; `home/AppData/Local/Programs/Vim/_vimrc` and `home/AppData/Local/nvim/init.lua` at their real `%LOCALAPPDATA%` locations on Windows. `home/AppData/Local/nvim/` also keeps Neovim's lockfiles plus `scripts/` and `snippets/`, which only Windows reads. +- Platform ownership is explicit in both linkers: `script/link` / `script/check` skip `home/AppData/` on POSIX, and `script/link.ps1` skips `home/.vimrc` and `home/.config/nvim/` on Windows. Skipped sources are never deleted — a machine that already linked them keeps its symlinks untouched. `set background=transparent` is rejected with E474 by both Vim and Neovim, so transparency is applied as `guibg=NONE` on `Normal` / `NormalNC` / `SignColumn` / `EndOfBuffer`, re-applied on `ColorScheme`. diff --git a/home/.config/nvim/init.lua b/home/.config/nvim/init.lua new file mode 100644 index 0000000..5c50561 --- /dev/null +++ b/home/.config/nvim/init.lua @@ -0,0 +1,11 @@ +-- Thin Neovim entry point. Windows reads it from %LOCALAPPDATA%\nvim +-- (home/AppData/Local/nvim/init.lua), POSIX from ~/.config/nvim +-- (home/.config/nvim/init.lua); the two files are byte-identical on purpose +-- and source the one canonical config, home/vimfiles/nvim/init.lua, so the +-- 281-line configuration is never duplicated across operating systems. +local shared = vim.fn.expand("~/vimfiles/nvim/init.lua") +if vim.fn.filereadable(shared) == 1 then + vim.cmd.source(shared) +else + vim.notify("dotfiles: missing " .. shared .. " (run script/link)", vim.log.levels.WARN) +end diff --git a/home/.vimrc b/home/.vimrc new file mode 100644 index 0000000..d4fd879 --- /dev/null +++ b/home/.vimrc @@ -0,0 +1,22 @@ +" POSIX entry point for Vim. Windows uses the install-dir entry at +" home/AppData/Local/Programs/Vim/_vimrc; both files only source shared +" configuration, nothing is configured here. +" +" vimrc_example.vim is the portable runtime template (its own header says +" "for Unix: ~/.vimrc") and it pulls in $VIMRUNTIME/defaults.vim. Sourcing it +" matters on Unix: with a user vimrc present Vim no longer auto-loads +" defaults.vim, so skipping the template would regress scrolloff/mouse/ttimeout +" that this machine has today. base.vim runs last and overrides every option it +" shares with the template, in the same order as the Windows entry. +if filereadable(expand('$VIMRUNTIME/vimrc_example.vim')) + source $VIMRUNTIME/vimrc_example.vim +endif + +" The Windows-only `set diffexpr=MyDiff()` block is intentionally skipped: +" Vim 9 lists 'internal' in 'diffopt' on every platform (verified: +" diffopt=internal,filler,...), so MyDiff never runs on Windows either. + +" 共通設定 (大西配列のキーマップ・背景透過を含む) +if filereadable(expand("~/vimfiles/shared/base.vim")) + source ~/vimfiles/shared/base.vim +endif diff --git a/home/AppData/Local/nvim/init.lua b/home/AppData/Local/nvim/init.lua index 1272bd4..5c50561 100644 --- a/home/AppData/Local/nvim/init.lua +++ b/home/AppData/Local/nvim/init.lua @@ -1,281 +1,11 @@ -local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" - -if not vim.loop.fs_stat(lazypath) then - vim.fn.system({ - "git", - "clone", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", - lazypath, - }) -end - -vim.opt.rtp:prepend(lazypath) - --- 起動時パフォーマンス: 未使用providerを無効化 -vim.g.loaded_perl_provider = 0 -vim.g.loaded_ruby_provider = 0 -vim.g.loaded_node_provider = 0 -vim.g.loaded_python3_provider = 0 - -vim.opt.shadafile = "NONE" -vim.opt.updatetime = 300 -vim.opt.signcolumn = "yes" -vim.opt.lazyredraw = false - -require("lazy").setup({ - spec = { - -- 補完(blink.cmpは内部で遅延) - { - "saghen/blink.cmp", - version = "1.*", - dependencies = { - "rafamadriz/friendly-snippets", - }, - event = { "BufReadPost", "BufNewFile" }, - opts = { - -- キー設定は下で明示("preset = none"にして競合を避ける) - keymap = { - preset = "none", - [""] = { "select_next", "fallback" }, - [""] = { "select_prev", "fallback" }, - [""] = { "show", "fallback" }, - [""] = { "hide", "fallback" }, - [""] = { "scroll_documentation_down", "fallback" }, - [""] = { "scroll_documentation_up", "fallback" }, - -- Tab / Enter / Shift-Tab は下のsmart_key()で一元処理 - }, - completion = { - documentation = { - auto_show = true, - }, - }, - sources = { - default = { - "lsp", - "path", - "snippets", - "buffer", - }, - }, - }, - }, - - -- Git差分表示(バッファ読込時のみ) - { - "lewis6991/gitsigns.nvim", - event = { "BufReadPost", "BufNewFile" }, - opts = {}, - }, - - -- ファイル・全文検索(コマンド起動時のみ) - { - "nvim-telescope/telescope.nvim", - cmd = "Telescope", - keys = { - { "ff", "Telescope find_files", desc = "Find files" }, - { "fg", "Telescope live_grep", desc = "Live grep" }, - { "fb", "Telescope buffers", desc = "Buffers" }, - { "fh", "Telescope help_tags", desc = "Help tags" }, - }, - dependencies = { - "nvim-lua/plenary.nvim", - }, - }, - - -- formatter(保存時のみ) - { - "stevearc/conform.nvim", - event = { "BufWritePre" }, - cmd = { "ConformInfo" }, - opts = { - format_on_save = { - timeout_ms = 1000, - lsp_format = "fallback", - }, - - formatters_by_ft = { - rust = { "rustfmt" }, - lua = { "stylua" }, - }, - }, - }, - - -- MasonはUI用、使うときだけ起動 - { - "mason-org/mason.nvim", - cmd = { "Mason", "MasonInstall", "MasonUninstall", "MasonUpdate" }, - keys = { - { "mi", "MasonInstall", desc = "Mason install" }, - }, - opts = {}, - }, - - { - "neovim/nvim-lspconfig", - event = { "BufReadPost", "BufNewFile" }, - }, - }, -}) - -vim.lsp.enable({ - "rust_analyzer", - "lua_ls", -}) - --- rust-analyzer: 型ヒント有効、リアルタイム診断有効、起動は軽量化 -vim.lsp.config("rust_analyzer", { - settings = { - ["rust-analyzer"] = { - inlayHints = { - enable = true, - parameterHints = true, - typeHints = true, - chainingHints = true, - closingBraceHints = true, - macroHints = true, - }, - check = { - workspace = false, - command = "clippy", - }, - cargo = { - allFeatures = false, - buildScripts = false, - }, - completion = { - autoimport = { enable = false }, - }, - imports = { - granularity = "Item", - group = true, - }, - diagnostics = { - enable = true, - experimental = { enable = true }, - }, - }, - }, -}) - --- inlay hintsトグル(\ih) -vim.keymap.set("n", "ih", function() - local ih = vim.lsp.inlay_hint or vim.lsp.buf and vim.lsp.buf.inlay_hint - -- nvim 0.10+: vim.lsp.inlay_hint.is_enabled() - if vim.lsp.inlay_hint then - if vim.lsp.inlay_hint.is_enabled({ bufnr = 0 }) then - vim.lsp.inlay_hint.disable({ bufnr = 0 }) - else - vim.lsp.inlay_hint.enable({ bufnr = 0 }) - end - end -end, { desc = "toggle inlay hints" }) - --- ============================================================= --- 補完キーマップ(明示) --- ============================================================= --- 優先順位: --- 1. snippet placeholder内 → vim.snippet.jump (Tab/Shift-Tab) --- 2. blink.cmpの補完メニュー表示中 → accept / select_prev (Tab/Enter/Shift-Tab) --- 3. それ以外 → 通常のキー入力をそのまま流す --- --- Tab 補完確定 / snippet次 / 通常のTab --- Shift+Tab 補完prev / snippet前 / 通常のShift+Tab --- Enter 補完確定 / 通常の改行 --- C-n/p 補完候補を次/前 --- C-Space 補完メニューを手動で開く --- C-e 補完メニューを閉じる --- ============================================================= - -local function smart_key(key) - return function() - -- 1. snippet placeholderへのジャンプを優先 - if vim.snippet and vim.snippet.jumpable and vim.snippet.jumpable(1) then - vim.snippet.jump(1) - return - end - -- 2. 補完メニュー表示中ならaccept - local ok, cmp = pcall(require, "blink.cmp") - if ok and cmp.is_visible() then - cmp.accept({}) - return - end - -- 3. それ以外は通常のキー入力をそのまま流す - local keys = vim.api.nvim_replace_termcodes(key, true, false, true) - vim.api.nvim_feedkeys(keys, "n", false) - end -end - -vim.keymap.set("i", "", smart_key(""), { desc = "Tab: snippet→cmp→fallback" }) -vim.keymap.set("i", "", function() - if vim.snippet and vim.snippet.jumpable and vim.snippet.jumpable(-1) then - vim.snippet.jump(-1) - return - end - local ok, cmp = pcall(require, "blink.cmp") - if ok and cmp.is_visible() then - cmp.select_prev() - return - end - local keys = vim.api.nvim_replace_termcodes("", true, false, true) - vim.api.nvim_feedkeys(keys, "n", false) -end, { desc = "Shift-Tab: snippet→cmp prev→fallback" }) - -vim.keymap.set("i", "", smart_key(""), { desc = "Enter: cmp accept→fallback" }) - --- リアルタイム診断: virtual_text / signs を明示有効化 -vim.diagnostic.config({ - virtual_text = { - prefix = "■", - spacing = 2, - source = true, -- どのLSP由来か表示 - }, - signs = true, - severity_sort = true, - underline = true, - float = { - source = true, - border = "rounded", - }, - update_in_insert = false, -- 入力中は更新しない(重くしない) -}) - --- Cargo(競プロ用ターミナル開閉ヘルパー) -local function cargo_compete(cmd) - if vim.fn.executable("cargo") == 0 then - vim.notify("cargo not found", vim.log.levels.WARN) - return - end - local term_cmd = "cargo compete" .. (cmd and (" " .. cmd) or "") - vim.cmd("botright split") - vim.cmd("terminal " .. term_cmd) - local term_buf = vim.api.nvim_get_current_buf() - - -- ターミナルが閉じられたら現在のバッファをrustfmtでフォーマット - vim.api.nvim_create_autocmd({ "BufWinLeave", "WinClosed" }, { - buffer = term_buf, - once = true, - nested = true, - callback = function() - vim.schedule(function() - local ok, conform = pcall(require, "conform") - if ok then - conform.format({ async = true, lsp_format = "fallback" }) - end - end) - end, - }) -end - -vim.keymap.set("n", "an", function() cargo_compete("new") end, { desc = "cargo compete new" }) -vim.keymap.set("n", "ac", function() cargo_compete("") end, { desc = "cargo compete (interactive)" }) -vim.keymap.set("n", "at", function() cargo_compete("test") end, { desc = "cargo compete test" }) -vim.keymap.set("n", "as", function() cargo_compete("submit") end, { desc = "cargo compete submit" }) - --- 背景の透過と大西配列のキーマップは ~/vimfiles/shared/base.vim に集約している --- (Vim 側の _vimrc と同じファイルを読み込む)。 -local shared = vim.fn.expand("~/vimfiles/shared/base.vim") +-- Thin Neovim entry point. Windows reads it from %LOCALAPPDATA%\nvim +-- (home/AppData/Local/nvim/init.lua), POSIX from ~/.config/nvim +-- (home/.config/nvim/init.lua); the two files are byte-identical on purpose +-- and source the one canonical config, home/vimfiles/nvim/init.lua, so the +-- 281-line configuration is never duplicated across operating systems. +local shared = vim.fn.expand("~/vimfiles/nvim/init.lua") if vim.fn.filereadable(shared) == 1 then vim.cmd.source(shared) +else + vim.notify("dotfiles: missing " .. shared .. " (run script/link)", vim.log.levels.WARN) end diff --git a/home/vimfiles/nvim/init.lua b/home/vimfiles/nvim/init.lua new file mode 100644 index 0000000..f0df707 --- /dev/null +++ b/home/vimfiles/nvim/init.lua @@ -0,0 +1,281 @@ +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" + +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", + lazypath, + }) +end + +vim.opt.rtp:prepend(lazypath) + +-- 起動時パフォーマンス: 未使用providerを無効化 +vim.g.loaded_perl_provider = 0 +vim.g.loaded_ruby_provider = 0 +vim.g.loaded_node_provider = 0 +vim.g.loaded_python3_provider = 0 + +vim.opt.shadafile = "NONE" +vim.opt.updatetime = 300 +vim.opt.signcolumn = "yes" +vim.opt.lazyredraw = false + +require("lazy").setup({ + spec = { + -- 補完(blink.cmpは内部で遅延) + { + "saghen/blink.cmp", + version = "1.*", + dependencies = { + "rafamadriz/friendly-snippets", + }, + event = { "BufReadPost", "BufNewFile" }, + opts = { + -- キー設定は下で明示("preset = none"にして競合を避ける) + keymap = { + preset = "none", + [""] = { "select_next", "fallback" }, + [""] = { "select_prev", "fallback" }, + [""] = { "show", "fallback" }, + [""] = { "hide", "fallback" }, + [""] = { "scroll_documentation_down", "fallback" }, + [""] = { "scroll_documentation_up", "fallback" }, + -- Tab / Enter / Shift-Tab は下のsmart_key()で一元処理 + }, + completion = { + documentation = { + auto_show = true, + }, + }, + sources = { + default = { + "lsp", + "path", + "snippets", + "buffer", + }, + }, + }, + }, + + -- Git差分表示(バッファ読込時のみ) + { + "lewis6991/gitsigns.nvim", + event = { "BufReadPost", "BufNewFile" }, + opts = {}, + }, + + -- ファイル・全文検索(コマンド起動時のみ) + { + "nvim-telescope/telescope.nvim", + cmd = "Telescope", + keys = { + { "ff", "Telescope find_files", desc = "Find files" }, + { "fg", "Telescope live_grep", desc = "Live grep" }, + { "fb", "Telescope buffers", desc = "Buffers" }, + { "fh", "Telescope help_tags", desc = "Help tags" }, + }, + dependencies = { + "nvim-lua/plenary.nvim", + }, + }, + + -- formatter(保存時のみ) + { + "stevearc/conform.nvim", + event = { "BufWritePre" }, + cmd = { "ConformInfo" }, + opts = { + format_on_save = { + timeout_ms = 1000, + lsp_format = "fallback", + }, + + formatters_by_ft = { + rust = { "rustfmt" }, + lua = { "stylua" }, + }, + }, + }, + + -- MasonはUI用、使うときだけ起動 + { + "mason-org/mason.nvim", + cmd = { "Mason", "MasonInstall", "MasonUninstall", "MasonUpdate" }, + keys = { + { "mi", "MasonInstall", desc = "Mason install" }, + }, + opts = {}, + }, + + { + "neovim/nvim-lspconfig", + event = { "BufReadPost", "BufNewFile" }, + }, + }, +}) + +vim.lsp.enable({ + "rust_analyzer", + "lua_ls", +}) + +-- rust-analyzer: 型ヒント有効、リアルタイム診断有効、起動は軽量化 +vim.lsp.config("rust_analyzer", { + settings = { + ["rust-analyzer"] = { + inlayHints = { + enable = true, + parameterHints = true, + typeHints = true, + chainingHints = true, + closingBraceHints = true, + macroHints = true, + }, + check = { + workspace = false, + command = "clippy", + }, + cargo = { + allFeatures = false, + buildScripts = false, + }, + completion = { + autoimport = { enable = false }, + }, + imports = { + granularity = "Item", + group = true, + }, + diagnostics = { + enable = true, + experimental = { enable = true }, + }, + }, + }, +}) + +-- inlay hintsトグル(\ih) +vim.keymap.set("n", "ih", function() + local ih = vim.lsp.inlay_hint or vim.lsp.buf and vim.lsp.buf.inlay_hint + -- nvim 0.10+: vim.lsp.inlay_hint.is_enabled() + if vim.lsp.inlay_hint then + if vim.lsp.inlay_hint.is_enabled({ bufnr = 0 }) then + vim.lsp.inlay_hint.disable({ bufnr = 0 }) + else + vim.lsp.inlay_hint.enable({ bufnr = 0 }) + end + end +end, { desc = "toggle inlay hints" }) + +-- ============================================================= +-- 補完キーマップ(明示) +-- ============================================================= +-- 優先順位: +-- 1. snippet placeholder内 → vim.snippet.jump (Tab/Shift-Tab) +-- 2. blink.cmpの補完メニュー表示中 → accept / select_prev (Tab/Enter/Shift-Tab) +-- 3. それ以外 → 通常のキー入力をそのまま流す +-- +-- Tab 補完確定 / snippet次 / 通常のTab +-- Shift+Tab 補完prev / snippet前 / 通常のShift+Tab +-- Enter 補完確定 / 通常の改行 +-- C-n/p 補完候補を次/前 +-- C-Space 補完メニューを手動で開く +-- C-e 補完メニューを閉じる +-- ============================================================= + +local function smart_key(key) + return function() + -- 1. snippet placeholderへのジャンプを優先 + if vim.snippet and vim.snippet.jumpable and vim.snippet.jumpable(1) then + vim.snippet.jump(1) + return + end + -- 2. 補完メニュー表示中ならaccept + local ok, cmp = pcall(require, "blink.cmp") + if ok and cmp.is_visible() then + cmp.accept({}) + return + end + -- 3. それ以外は通常のキー入力をそのまま流す + local keys = vim.api.nvim_replace_termcodes(key, true, false, true) + vim.api.nvim_feedkeys(keys, "n", false) + end +end + +vim.keymap.set("i", "", smart_key(""), { desc = "Tab: snippet→cmp→fallback" }) +vim.keymap.set("i", "", function() + if vim.snippet and vim.snippet.jumpable and vim.snippet.jumpable(-1) then + vim.snippet.jump(-1) + return + end + local ok, cmp = pcall(require, "blink.cmp") + if ok and cmp.is_visible() then + cmp.select_prev() + return + end + local keys = vim.api.nvim_replace_termcodes("", true, false, true) + vim.api.nvim_feedkeys(keys, "n", false) +end, { desc = "Shift-Tab: snippet→cmp prev→fallback" }) + +vim.keymap.set("i", "", smart_key(""), { desc = "Enter: cmp accept→fallback" }) + +-- リアルタイム診断: virtual_text / signs を明示有効化 +vim.diagnostic.config({ + virtual_text = { + prefix = "■", + spacing = 2, + source = true, -- どのLSP由来か表示 + }, + signs = true, + severity_sort = true, + underline = true, + float = { + source = true, + border = "rounded", + }, + update_in_insert = false, -- 入力中は更新しない(重くしない) +}) + +-- Cargo(競プロ用ターミナル開閉ヘルパー) +local function cargo_compete(cmd) + if vim.fn.executable("cargo") == 0 then + vim.notify("cargo not found", vim.log.levels.WARN) + return + end + local term_cmd = "cargo compete" .. (cmd and (" " .. cmd) or "") + vim.cmd("botright split") + vim.cmd("terminal " .. term_cmd) + local term_buf = vim.api.nvim_get_current_buf() + + -- ターミナルが閉じられたら現在のバッファをrustfmtでフォーマット + vim.api.nvim_create_autocmd({ "BufWinLeave", "WinClosed" }, { + buffer = term_buf, + once = true, + nested = true, + callback = function() + vim.schedule(function() + local ok, conform = pcall(require, "conform") + if ok then + conform.format({ async = true, lsp_format = "fallback" }) + end + end) + end, + }) +end + +vim.keymap.set("n", "an", function() cargo_compete("new") end, { desc = "cargo compete new" }) +vim.keymap.set("n", "ac", function() cargo_compete("") end, { desc = "cargo compete (interactive)" }) +vim.keymap.set("n", "at", function() cargo_compete("test") end, { desc = "cargo compete test" }) +vim.keymap.set("n", "as", function() cargo_compete("submit") end, { desc = "cargo compete submit" }) + +-- 背景の透過と大西配列のキーマップは ~/vimfiles/shared/base.vim に集約している +-- (Vim 側の .vimrc / _vimrc と同じファイルを読み込む)。 +local shared = vim.fn.expand("~/vimfiles/shared/base.vim") +if vim.fn.filereadable(shared) == 1 then + vim.cmd.source(shared) +end diff --git a/home/vimfiles/shared/base.vim b/home/vimfiles/shared/base.vim index fc905b5..49abce3 100644 --- a/home/vimfiles/shared/base.vim +++ b/home/vimfiles/shared/base.vim @@ -7,8 +7,8 @@ scriptencoding utf-8 " https://github.com/yasunori0418/dotfiles/blob/0fb4280199581af9a0b19cdea9f8c61a54f89c03/home/.vimrc " " 読み込み方: -" Vim : _vimrc から source -" Neovim : init.lua から vim.cmd('source ...') +" Vim : ~/.vimrc (POSIX) / _vimrc (Windows) から source +" Neovim : init.lua (薄い loader) → ~/vimfiles/nvim/init.lua から source " " Vim と Neovim で挙動が異なる設定 (文字コード、backup file) は " if has('nvim') で分けている。 @@ -180,7 +180,7 @@ syntax on " 端末の背景を透かす。 " 'background' に transparent を指定する書き方は Vim でも Neovim でも " E474 になるので、guibg=NONE でハイライト側だけ背景を落とす。 -" Vim 側 (_vimrc 経由) と Neovim 側 (init.lua 経由) で同じ関数を共有する。 +" Vim 側 (.vimrc / _vimrc 経由) と Neovim 側 (init.lua 経由) で同じ関数を共有する。 " :colorscheme で配色し直した後にも ColorScheme ごとに掛け直す。 function! s:TransparentBG() abort for s:hl in ['Normal', 'NormalNC', 'SignColumn', 'EndOfBuffer'] diff --git a/script/check b/script/check index cce6b8d..9b9f804 100755 --- a/script/check +++ b/script/check @@ -33,6 +33,7 @@ sources() { local name source relative first if [[ ${#unit_names[@]} -gt 0 ]]; then for name in "${unit_names[@]}"; do + is_platform_skipped "$name" && continue printf '%s\0' "$source_root/$name" done fi @@ -41,6 +42,7 @@ sources() { first="${relative%%/*}" is_unit_name "$first" && continue is_composer_owned "$relative" && continue + is_platform_skipped "$relative" && continue printf '%s\0' "$source" done < <(find "$source_root" \( -type f -o -type l \) -print0) } @@ -61,6 +63,16 @@ is_composer_owned() { return 1 } +# Mirrors script/link: AppData/ is the Windows %LOCALAPPDATA% layout and is +# not managed on POSIX, so it is neither linked nor reported as missing/drift. +is_platform_skipped() { + local relative="$1" + case "$relative" in + AppData|AppData/*) return 0 ;; + esac + return 1 +} + while IFS= read -r -d '' source; do relative="${source#"$source_root"/}" target="$target_root/$relative" diff --git a/script/link b/script/link index e81e465..fe41b24 100755 --- a/script/link +++ b/script/link @@ -39,6 +39,7 @@ sources() { local name source relative first if [[ ${#unit_names[@]} -gt 0 ]]; then for name in "${unit_names[@]}"; do + is_platform_skipped "$name" && continue printf '%s\0' "$source_root/$name" done fi @@ -47,6 +48,7 @@ sources() { first="${relative%%/*}" is_unit_name "$first" && continue is_composer_owned "$relative" && continue + is_platform_skipped "$relative" && continue printf '%s\0' "$source" done < <(find "$source_root" \( -type f -o -type l \) -print0) } @@ -67,6 +69,24 @@ is_composer_owned() { return 1 } +# Platform-specific managed entries. home/ mirrors $HOME, but AppData/ is the +# Windows %LOCALAPPDATA% layout: on macOS and WSL it means nothing, so it must +# never be linked into a POSIX HOME (macOS machines have historically ended up +# with a stray ~/AppData tree this way). +# +# A skipped source is never linked and never removed: a machine that linked +# AppData/ with an older script/link keeps those symlinks exactly as they are +# (linking stays non-destructive, see README "Principles"), and script/check +# stops reporting them. Deleting user state is not link's job; there is no flag +# that does it either. +is_platform_skipped() { + local relative="$1" + case "$relative" in + AppData|AppData/*) return 0 ;; + esac + return 1 +} + # Preflight every managed target before mutating HOME. A conflict anywhere # aborts the whole operation so linking never leaves a partial result. while IFS= read -r -d '' source; do diff --git a/script/link.ps1 b/script/link.ps1 index e0548e7..c355906 100644 --- a/script/link.ps1 +++ b/script/link.ps1 @@ -41,8 +41,15 @@ $PosixOnly = @{ '.local/bin/devices' = 'POSIX launcher; on Windows use script/devices.ps1' '.local/bin/agent' = 'POSIX symlink to agent.ts; on Windows use script/agent.ps1 and `agent shortcuts create`' '.claude/statusline-command.sh' = 'bash status line renderer; not wired for Windows-native Claude Code' + '.vimrc' = 'POSIX Vim entry point; Windows Vim reads the install-dir _vimrc under home/AppData/Local/Programs/Vim/_vimrc' + '.config/nvim/init.lua' = 'POSIX Neovim entry point; Windows Neovim reads %LOCALAPPDATA%\nvim\init.lua under home/AppData/Local/nvim/init.lua' } +# Directory-scoped POSIX-only trees. The table above matches exact paths only, +# so without this a future home/.config/nvim/ file would slip through and land +# in a Windows HOME that Neovim never reads. +$PosixOnlyPrefixes = @('.config/nvim/') + $SourceRoot = Join-Path $RepoRoot 'home' if (-not (Test-Path -LiteralPath $SourceRoot)) { [Console]::Error.WriteLine("missing managed source root: $SourceRoot") @@ -94,6 +101,15 @@ foreach ($entry in $entries) { continue } + $posixPrefix = '' + foreach ($prefix in $PosixOnlyPrefixes) { + if ($relative.StartsWith($prefix)) { $posixPrefix = $prefix; break } + } + if ($posixPrefix -ne '') { + Add-Result -State 'skip' -Relative $relative -Detail "POSIX-only tree $posixPrefix; Windows Neovim reads %LOCALAPPDATA%\nvim\init.lua" + continue + } + $workingCopy = Join-Path $SourceRoot ($relative -replace '/', '\') $isDirectoryLink = $false diff --git a/script/link.windows.test.ts b/script/link.windows.test.ts index f5eadc6..ad81505 100644 --- a/script/link.windows.test.ts +++ b/script/link.windows.test.ts @@ -31,19 +31,24 @@ function git(cwd: string, ...args: string[]) { function makeRepo(root: string, { initSubmodule }: { initSubmodule: boolean }) { const repo = join(root, "repo"); mkdirSync(join(repo, "home", ".config", "git"), { recursive: true }); + mkdirSync(join(repo, "home", ".config", "nvim"), { recursive: true }); mkdirSync(join(repo, "home", ".local", "bin"), { recursive: true }); mkdirSync(join(repo, "home", ".claude"), { recursive: true }); + mkdirSync(join(repo, "home", "AppData", "Local", "nvim"), { recursive: true }); mkdirSync(join(repo, "agents", "dsh"), { recursive: true }); git(repo, "init", "-q"); git(repo, "config", "core.symlinks", "false"); writeFileSync(join(repo, "home", ".gitconfig"), "[user]\n\tname = managed\n"); writeFileSync(join(repo, "home", ".config", "git", "ignore"), "*.log\n"); + writeFileSync(join(repo, "home", ".config", "nvim", "init.lua"), "-- POSIX Neovim entry point\n"); + writeFileSync(join(repo, "home", ".vimrc"), '" POSIX Vim entry point\n'); writeFileSync(join(repo, "home", ".local", "bin", "agent"), "#!/bin/sh\n"); writeFileSync(join(repo, "home", ".claude", "statusline-command.sh"), "#!/bin/sh\n"); + writeFileSync(join(repo, "home", "AppData", "Local", "nvim", "init.lua"), "-- Windows Neovim entry point\n"); // core.symlinks=false checkout of a symlink: a plain file holding the link text. writeFileSync(join(repo, "home", ".dsh"), "../agents/dsh"); if (initSubmodule) writeFileSync(join(repo, "agents", "dsh", "README"), "dsh\n"); - git(repo, "add", "-A", "--", "home/.gitconfig", "home/.config", "home/.local", "home/.claude"); + git(repo, "add", "-A", "--", "home/.gitconfig", "home/.config", "home/.vimrc", "home/.local", "home/.claude", "home/AppData"); const blob = git(repo, "hash-object", "-w", join(repo, "home", ".dsh")); git(repo, "update-index", "--add", "--cacheinfo", `120000,${blob},home/.dsh`); return repo; @@ -100,6 +105,14 @@ describeWin("link.ps1 (Windows adoption adapter)", () => { // POSIX-only entries are skipped, not linked expect(existsSync(join(home, ".local", "bin", "agent"))).toBe(false); expect(existsSync(join(home, ".claude", "statusline-command.sh"))).toBe(false); + expect(r.out).toContain("skip .local/bin/agent"); + // POSIX-only editor entry points: skipped with a printed reason, while + // the Windows-layout Neovim config is still linked on Windows. + expect(existsSync(join(home, ".vimrc"))).toBe(false); + expect(existsSync(join(home, ".config", "nvim", "init.lua"))).toBe(false); + expect(r.out).toContain("skip .vimrc"); + expect(r.out).toContain("skip .config/nvim/init.lua"); + expect(isLink(join(home, "AppData", "Local", "nvim", "init.lua"))).toBe(true); const again = link(repo, home, "-Apply"); expect(again.code).toBe(0); diff --git a/script/test b/script/test index e862a1c..23715b1 100755 --- a/script/test +++ b/script/test @@ -109,4 +109,59 @@ if XDG_CONFIG_HOME="$backup_home/.config" HOME="$backup_home" "$backup_repo/scri exit 1 fi +# Platform-aware linking: home/AppData is the Windows %LOCALAPPDATA% layout and +# must never be published into a POSIX HOME, while the Unix editor entry points +# (.vimrc, .config/nvim/init.lua) must be. check mirrors link, so the skipped +# tree must produce neither a link nor a missing/drift report. +platform_home="$tmp/platform-home" +platform_xdg="$platform_home/.config" +mkdir -p "$platform_home" +XDG_CONFIG_HOME="$platform_xdg" HOME="$platform_home" "$repo_root/script/link" >"$tmp/platform-link.log" 2>&1 +XDG_CONFIG_HOME="$platform_xdg" HOME="$platform_home" bun "$repo_root/script/claude-settings.ts" compose +if ! XDG_CONFIG_HOME="$platform_xdg" HOME="$platform_home" "$repo_root/script/check" >"$tmp/platform-check.log" 2>&1; then + cat "$tmp/platform-link.log" "$tmp/platform-check.log" >&2 + printf 'check failed for a POSIX HOME with AppData platform-skipped\n' >&2 + exit 1 +fi + +if [[ -e "$platform_home/AppData" || -L "$platform_home/AppData" ]]; then + printf 'link published the Windows-only AppData tree into a POSIX HOME\n' >&2 + exit 1 +fi +if grep -q 'AppData' "$tmp/platform-link.log" "$tmp/platform-check.log"; then + printf 'link/check still manage the platform-skipped AppData tree\n' >&2 + exit 1 +fi +if [[ "$(readlink "$platform_home/.vimrc")" != "$repo_root/home/.vimrc" ]]; then + printf 'link did not publish the Unix Vim entry point .vimrc\n' >&2 + exit 1 +fi +if [[ "$(readlink "$platform_home/.config/nvim/init.lua")" != "$repo_root/home/.config/nvim/init.lua" ]]; then + printf 'link did not publish the Unix Neovim entry point .config/nvim/init.lua\n' >&2 + exit 1 +fi + +# Non-destructive default for a now-skipped source: an AppData tree linked by +# an older script/link is left exactly as it is (never removed, never +# retargeted) and is no longer reported as missing or drift. +legacy_home="$tmp/legacy-appdata-home" +legacy_xdg="$legacy_home/.config" +mkdir -p "$legacy_home/AppData/Local/nvim" +ln -s "$repo_root/home/AppData/Local/nvim/init.lua" "$legacy_home/AppData/Local/nvim/init.lua" +XDG_CONFIG_HOME="$legacy_xdg" HOME="$legacy_home" "$repo_root/script/link" >"$tmp/legacy-link.log" 2>&1 +XDG_CONFIG_HOME="$legacy_xdg" HOME="$legacy_home" bun "$repo_root/script/claude-settings.ts" compose +if ! XDG_CONFIG_HOME="$legacy_xdg" HOME="$legacy_home" "$repo_root/script/check" >"$tmp/legacy-check.log" 2>&1; then + cat "$tmp/legacy-link.log" "$tmp/legacy-check.log" >&2 + printf 'check failed while a pre-existing AppData link was present\n' >&2 + exit 1 +fi +if [[ "$(readlink "$legacy_home/AppData/Local/nvim/init.lua")" != "$repo_root/home/AppData/Local/nvim/init.lua" ]]; then + printf 'link removed or retargeted a pre-existing AppData link\n' >&2 + exit 1 +fi +if grep -q 'AppData' "$tmp/legacy-link.log" "$tmp/legacy-check.log"; then + printf 'link/check still manage a pre-existing AppData link that is platform-skipped\n' >&2 + exit 1 +fi + printf 'symlink behavior tests passed\n' From f6b7826672e916183e499dd2577f0b60a073c0bc Mon Sep 17 00:00:00 2001 From: samuido Date: Thu, 5 Nov 2026 00:28:01 +0900 Subject: [PATCH 2/5] docs(link): document the Windows retarget procedure for stale feature-branch links --- README.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 309ca0e..221b8ee 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,26 @@ pwsh -NoProfile -File script/link.ps1 -Apply # target が存在しない entry - 既存ファイルは置換・移動・削除しない。内容が同一なら `identical`、異なる/別先を指す symlink は `conflict` として手動マージ対象に残す(`-Apply` は conflict が残ると終了コード 1)。 - symlink 権限が無い場合 (Developer Mode / 管理者が必要) は copy にフォールバックせず `error` を報告する。 - symlink entry は git index (mode 120000) から読む。`core.symlinks=false` では plain file として checkout されるため。 -- 未初期化 submodule の unit (`.dsh`) と POSIX 専用 entry (`.local/bin/agent`, `.claude/statusline-command.sh`) は理由付きで skip する。Windows の agent は `script/agent.ps1` と `agent shortcuts create` を使う。 +- 未初期化 submodule の unit (`.dsh`) と POSIX 専用 entry (`.local/bin/agent`, `.claude/statusline-command.sh`, `.vimrc`, `.config/nvim/`) は理由付きで skip する。Windows の agent は `script/agent.ps1` と `agent shortcuts create` を使う。 + +#### 既存リンクの配置先を `~\src\dotfiles` から `~\.dotfiles` に是正する + +古い配備では symlink が feature branch の checkout (`~\src\dotfiles`) を指したままになる。`link.ps1` は adoption-first なので、別先を指す symlink を勝手に張り替えず `conflict` として報告する。安全・再実行可能な是正手順 (この手順自体は各 Windows machine 上で実行する): + +```powershell +cd ~\.dotfiles +git switch main; git pull; git submodule update --init --recursive +pwsh -NoProfile -File script/link.ps1 # plan: `conflict … (symlink points to …)` が stale link の一覧 +# 各 conflict 行について、symlink であることを確認してから link 側だけ削除する +# (削除されるのは link で、~\src\dotfiles 側の実体は残る。実体ファイルなら何もしない) +$p = 'C:\Users\\.gitconfig' # conflict 行の 1 つに置き換える +$item = Get-Item -LiteralPath $p -Force +if ($item.LinkType) { $item.Delete() } else { "not a symlink, skipped: $p" } +pwsh -NoProfile -File script/link.ps1 -Apply # 欠けていた entry を ~\.dotfiles 向けに作成 +pwsh -NoProfile -File script/link.ps1 # 再計画: conflict が 0 で ok/identical のみなら完了 +``` + +手順は何度でも再実行できる (既存の link は触らず、欠けた entry だけ作る)。 ### Direct dotfiles recovery From 26c342750b1199eb29ceffe27ea4991aef642e8d Mon Sep 17 00:00:00 2001 From: samuido Date: Thu, 5 Nov 2026 00:41:11 +0900 Subject: [PATCH 3/5] test(link.windows): bind the run result used by the POSIX-skip assertions The fresh-HOME apply test invoked link() inline (expect(link(...).code)), so the r.out assertions added for the POSIX-only entry points referenced an unbound identifier and failed with ReferenceError on the windows-agent job. --- script/link.windows.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/script/link.windows.test.ts b/script/link.windows.test.ts index ad81505..f510238 100644 --- a/script/link.windows.test.ts +++ b/script/link.windows.test.ts @@ -96,7 +96,8 @@ describeWin("link.ps1 (Windows adoption adapter)", () => { const repo = makeRepo(root, { initSubmodule: true }); const home = join(root, "home"); mkdirSync(home); - expect(link(repo, home, "-Apply").code).toBe(0); + const r = link(repo, home, "-Apply"); + expect(r.code).toBe(0); expect(isLink(join(home, ".gitconfig"))).toBe(true); expect(realpathSync.native(join(home, ".gitconfig"))).toBe(realpathSync.native(join(repo, "home", ".gitconfig"))); // a directory unit is linked to the resolved agents/dsh checkout From 618edd67a8910b13b45d0b3cee7f9a75be361051 Mon Sep 17 00:00:00 2001 From: samuido Date: Thu, 5 Nov 2026 01:23:30 +0900 Subject: [PATCH 4/5] fix(vim): capability-probe the diffopt flags in shared/base.vim Apple's system vim (a 9.1 build that lacks the internal-diff option items even though it reports +diff) rejects algorithm:histogram and indent-heuristic with E474 on base.vim's diffopt line. The error print raises a hit-enter prompt that aborts batch invocations (vim --not-a-term -c ...) before their -c commands run, and the diff options are silently lost. Ubuntu's vim accepts the items, which is why the WSL run was clean; the macOS leg exposed it. Apply the blanket set inside try/catch first so supporting builds take the exact same code path and end with a byte-identical &diffopt: the single-item += form is a no-op for an already-present flag, so a plain per-item rewrite would drop the trailing duplicate indent-heuristic that the blanket line appends (verified: before/after strings identical on Ubuntu vim). When the build rejects the list, fall back to per-item application so an unsupported build loses only those items and prints nothing. --- home/vimfiles/shared/base.vim | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/home/vimfiles/shared/base.vim b/home/vimfiles/shared/base.vim index 49abce3..1228501 100644 --- a/home/vimfiles/shared/base.vim +++ b/home/vimfiles/shared/base.vim @@ -66,7 +66,25 @@ if !has('win32') && !has('win64') endif " diff を縦並び・行の差を強調 -set diffopt+=vertical,algorithm:histogram,indent-heuristic +" Apple のシステム vim (internal-diff option items を持たない 9.1 ビルド) は +" algorithm:/indent-heuristic を E474 で拒否し、エラー表示の hit-enter で +" batch 起動 (vim --not-a-term -c ...) が中断する。まず一括で適用し、 +" 拒否された場合だけ項目ごとに再適用して、未対応の項目だけを失う。 +" 対応済みビルドは一括側が成功するため &diffopt は従来と一字一句同じ結果に +" なる (diffopt+= の単一項目追加は既存フラグに対して no-op なので、 +" 既存の重複を含む文字列まで再現できる)。 +try + set diffopt+=vertical,algorithm:histogram,indent-heuristic +catch /^Vim\%((\a\+)\)\=:E474/ + for s:diffopt_item in ['vertical', 'algorithm:histogram', 'indent-heuristic'] + try + execute 'set diffopt+=' . s:diffopt_item + catch /^Vim\%((\a\+)\)\=:E474/ + " この vim ビルドは当該項目をサポートしていない + endtry + endfor + unlet s:diffopt_item +endtry " ビープを鳴らさない set belloff=all From 944a8788ba04e73c962060bdf45f712f163e008d Mon Sep 17 00:00:00 2001 From: samuido Date: Thu, 5 Nov 2026 11:49:53 +0900 Subject: [PATCH 5/5] test(link): cover the prefix-skip branch and harden the POSIX platform checks OCR review of this PR, five findings fixed: - link.ps1: $PosixOnlyPrefixes becomes a prefix -> reason hashtable so the prefix branch prints the looked-up reason instead of a hard-coded Neovim rationale; longest prefix wins if rules ever nest. - link.windows.test.ts: the fixture gains home/.config/nvim/lua/plugins.lua, which the exact table cannot match, so the prefix branch is reachable from tests. Assert both skip lines, the shared prefix reason, and that nothing is published under home/.config/nvim/. - script/test: both bare script/link invocations are wrapped so a non-zero exit prints the captured log before the EXIT trap removes $tmp. - script/test: the raw `grep -q AppData` assertions become a management-action pattern (missing|drift|ok|linked|conflict), so a legitimate skip reason that mentions AppData no longer fails them. - script/test: negative control for the skip itself -- remove a managed target and require check to fail and name it, so an over-matching is_platform_skipped (sources() emitting nothing, check exiting 0 on every HOME) can never pass silently. --- script/link.ps1 | 21 +++++++++++--------- script/link.windows.test.ts | 10 +++++++++- script/test | 39 +++++++++++++++++++++++++++++++------ 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/script/link.ps1 b/script/link.ps1 index c355906..a731d14 100644 --- a/script/link.ps1 +++ b/script/link.ps1 @@ -45,10 +45,13 @@ $PosixOnly = @{ '.config/nvim/init.lua' = 'POSIX Neovim entry point; Windows Neovim reads %LOCALAPPDATA%\nvim\init.lua under home/AppData/Local/nvim/init.lua' } -# Directory-scoped POSIX-only trees. The table above matches exact paths only, -# so without this a future home/.config/nvim/ file would slip through and land -# in a Windows HOME that Neovim never reads. -$PosixOnlyPrefixes = @('.config/nvim/') +# Directory-scoped POSIX-only trees, prefix -> reason (same printed-reason +# contract as $PosixOnly). The table above matches exact paths only, so without +# this any other file under home/.config/nvim/ would slip through and land in a +# Windows HOME that Neovim never reads. Longest prefix wins when rules nest. +$PosixOnlyPrefixes = @{ + '.config/nvim/' = 'POSIX-only Neovim tree; Windows Neovim reads %LOCALAPPDATA%\nvim\init.lua' +} $SourceRoot = Join-Path $RepoRoot 'home' if (-not (Test-Path -LiteralPath $SourceRoot)) { @@ -101,12 +104,12 @@ foreach ($entry in $entries) { continue } - $posixPrefix = '' - foreach ($prefix in $PosixOnlyPrefixes) { - if ($relative.StartsWith($prefix)) { $posixPrefix = $prefix; break } + $posixReason = '' + foreach ($prefix in ($PosixOnlyPrefixes.Keys | Sort-Object { -$_.Length })) { + if ($relative.StartsWith($prefix)) { $posixReason = $PosixOnlyPrefixes[$prefix]; break } } - if ($posixPrefix -ne '') { - Add-Result -State 'skip' -Relative $relative -Detail "POSIX-only tree $posixPrefix; Windows Neovim reads %LOCALAPPDATA%\nvim\init.lua" + if ($posixReason -ne '') { + Add-Result -State 'skip' -Relative $relative -Detail $posixReason continue } diff --git a/script/link.windows.test.ts b/script/link.windows.test.ts index f510238..aab56f1 100644 --- a/script/link.windows.test.ts +++ b/script/link.windows.test.ts @@ -31,7 +31,7 @@ function git(cwd: string, ...args: string[]) { function makeRepo(root: string, { initSubmodule }: { initSubmodule: boolean }) { const repo = join(root, "repo"); mkdirSync(join(repo, "home", ".config", "git"), { recursive: true }); - mkdirSync(join(repo, "home", ".config", "nvim"), { recursive: true }); + mkdirSync(join(repo, "home", ".config", "nvim", "lua"), { recursive: true }); mkdirSync(join(repo, "home", ".local", "bin"), { recursive: true }); mkdirSync(join(repo, "home", ".claude"), { recursive: true }); mkdirSync(join(repo, "home", "AppData", "Local", "nvim"), { recursive: true }); @@ -41,6 +41,9 @@ function makeRepo(root: string, { initSubmodule }: { initSubmodule: boolean }) { writeFileSync(join(repo, "home", ".gitconfig"), "[user]\n\tname = managed\n"); writeFileSync(join(repo, "home", ".config", "git", "ignore"), "*.log\n"); writeFileSync(join(repo, "home", ".config", "nvim", "init.lua"), "-- POSIX Neovim entry point\n"); + // Not in the $PosixOnly exact table: only the $PosixOnlyPrefixes branch can + // skip this file, so the fixture gives that branch real coverage. + writeFileSync(join(repo, "home", ".config", "nvim", "lua", "plugins.lua"), "-- prefix-skip fixture\n"); writeFileSync(join(repo, "home", ".vimrc"), '" POSIX Vim entry point\n'); writeFileSync(join(repo, "home", ".local", "bin", "agent"), "#!/bin/sh\n"); writeFileSync(join(repo, "home", ".claude", "statusline-command.sh"), "#!/bin/sh\n"); @@ -112,7 +115,12 @@ describeWin("link.ps1 (Windows adoption adapter)", () => { expect(existsSync(join(home, ".vimrc"))).toBe(false); expect(existsSync(join(home, ".config", "nvim", "init.lua"))).toBe(false); expect(r.out).toContain("skip .vimrc"); + // exact-table branch ($PosixOnly) and prefix branch ($PosixOnlyPrefixes) + // both skip, and neither publishes anything under home/.config/nvim/ expect(r.out).toContain("skip .config/nvim/init.lua"); + expect(r.out).toContain("skip .config/nvim/lua/plugins.lua"); + expect(r.out).toContain("POSIX-only Neovim tree"); + expect(existsSync(join(home, ".config", "nvim"))).toBe(false); expect(isLink(join(home, "AppData", "Local", "nvim", "init.lua"))).toBe(true); const again = link(repo, home, "-Apply"); diff --git a/script/test b/script/test index 23715b1..e0cb211 100755 --- a/script/test +++ b/script/test @@ -116,7 +116,11 @@ fi platform_home="$tmp/platform-home" platform_xdg="$platform_home/.config" mkdir -p "$platform_home" -XDG_CONFIG_HOME="$platform_xdg" HOME="$platform_home" "$repo_root/script/link" >"$tmp/platform-link.log" 2>&1 +if ! XDG_CONFIG_HOME="$platform_xdg" HOME="$platform_home" "$repo_root/script/link" >"$tmp/platform-link.log" 2>&1; then + cat "$tmp/platform-link.log" >&2 + printf 'link failed for a POSIX HOME with AppData platform-skipped\n' >&2 + exit 1 +fi XDG_CONFIG_HOME="$platform_xdg" HOME="$platform_home" bun "$repo_root/script/claude-settings.ts" compose if ! XDG_CONFIG_HOME="$platform_xdg" HOME="$platform_home" "$repo_root/script/check" >"$tmp/platform-check.log" 2>&1; then cat "$tmp/platform-link.log" "$tmp/platform-check.log" >&2 @@ -128,8 +132,11 @@ if [[ -e "$platform_home/AppData" || -L "$platform_home/AppData" ]]; then printf 'link published the Windows-only AppData tree into a POSIX HOME\n' >&2 exit 1 fi -if grep -q 'AppData' "$tmp/platform-link.log" "$tmp/platform-check.log"; then - printf 'link/check still manage the platform-skipped AppData tree\n' >&2 +# Management actions only: a skip reason may legitimately mention AppData +# (link.ps1 spells out the Windows path it is skipping for), so a bare +# 'AppData' match would assert the wrong invariant. +if grep -Eq '^(missing|drift|ok|linked|conflict)[[:space:]].*AppData' "$tmp/platform-link.log" "$tmp/platform-check.log"; then + printf 'link/check reported a management action for the platform-skipped AppData tree\n' >&2 exit 1 fi if [[ "$(readlink "$platform_home/.vimrc")" != "$repo_root/home/.vimrc" ]]; then @@ -141,6 +148,22 @@ if [[ "$(readlink "$platform_home/.config/nvim/init.lua")" != "$repo_root/home/. exit 1 fi +# Negative control for the skip itself: if is_platform_skipped over-matched +# (a catch-all pattern), sources() would emit nothing, check would exit 0 on +# every HOME, and every assertion above would still pass. Removing a managed +# target must make check fail and name it (check prints `missing `). +rm "$platform_home/.vimrc" +if XDG_CONFIG_HOME="$platform_xdg" HOME="$platform_home" "$repo_root/script/check" >"$tmp/platform-check-missing.log" 2>&1; then + cat "$tmp/platform-check-missing.log" >&2 + printf 'check passed with a managed target missing (sources() skip is over-matching)\n' >&2 + exit 1 +fi +if ! grep -q 'missing .*\.vimrc' "$tmp/platform-check-missing.log"; then + cat "$tmp/platform-check-missing.log" >&2 + printf 'check did not report the removed .vimrc as missing\n' >&2 + exit 1 +fi + # Non-destructive default for a now-skipped source: an AppData tree linked by # an older script/link is left exactly as it is (never removed, never # retargeted) and is no longer reported as missing or drift. @@ -148,7 +171,11 @@ legacy_home="$tmp/legacy-appdata-home" legacy_xdg="$legacy_home/.config" mkdir -p "$legacy_home/AppData/Local/nvim" ln -s "$repo_root/home/AppData/Local/nvim/init.lua" "$legacy_home/AppData/Local/nvim/init.lua" -XDG_CONFIG_HOME="$legacy_xdg" HOME="$legacy_home" "$repo_root/script/link" >"$tmp/legacy-link.log" 2>&1 +if ! XDG_CONFIG_HOME="$legacy_xdg" HOME="$legacy_home" "$repo_root/script/link" >"$tmp/legacy-link.log" 2>&1; then + cat "$tmp/legacy-link.log" >&2 + printf 'link failed while a pre-existing AppData link was present\n' >&2 + exit 1 +fi XDG_CONFIG_HOME="$legacy_xdg" HOME="$legacy_home" bun "$repo_root/script/claude-settings.ts" compose if ! XDG_CONFIG_HOME="$legacy_xdg" HOME="$legacy_home" "$repo_root/script/check" >"$tmp/legacy-check.log" 2>&1; then cat "$tmp/legacy-link.log" "$tmp/legacy-check.log" >&2 @@ -159,8 +186,8 @@ if [[ "$(readlink "$legacy_home/AppData/Local/nvim/init.lua")" != "$repo_root/ho printf 'link removed or retargeted a pre-existing AppData link\n' >&2 exit 1 fi -if grep -q 'AppData' "$tmp/legacy-link.log" "$tmp/legacy-check.log"; then - printf 'link/check still manage a pre-existing AppData link that is platform-skipped\n' >&2 +if grep -Eq '^(missing|drift|ok|linked|conflict)[[:space:]].*AppData' "$tmp/legacy-link.log" "$tmp/legacy-check.log"; then + printf 'link/check reported a management action for the platform-skipped pre-existing AppData link\n' >&2 exit 1 fi