Skip to content

Commit 8c539b9

Browse files
committed
fix: use literal path comparison instead of bufnr pattern match
vim.fn.bufnr(name) treats the name as a file-pattern (partial+regex match per :h bufname()), not a literal string. Paths with regex metacharacters like [ ] * ? { } match the wrong buffer or fail. Iterate nvim_list_bufs() and compare canonicalized paths via fs_realpath (with fnamemodify as fallback for buffers whose on-disk path doesn't exist yet). Also scope checktime to the matched buffer number instead of checking all buffers.
1 parent 6c9c52c commit 8c539b9

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

bin/claude-close-diff.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ fi
2323
# Extract file path for post-close reveal
2424
FILE_PATH="$(echo "$INPUT" | jq -r '.tool_input.file_path // empty' 2>/dev/null || true)"
2525

26-
# Reload nvim buffer Claude edited to display changes without refocus, other open buffers not affected
26+
# Reload nvim buffer Claude edited to display changes without refocus, other open buffers not affected.
27+
# We iterate vim.api.nvim_list_bufs() and compare canonical paths instead of using
28+
# vim.fn.bufnr(path), which does partial+regex matching on buffer names and mis-matches
29+
# paths containing regex metacharacters (e.g. /tmp/foo[1].md).
2730
if [[ -n "$FILE_PATH" ]]; then
2831
FILE_PATH_ESC="$(escape_lua "$FILE_PATH")"
29-
nvim_send "local buf = vim.fn.bufnr('$FILE_PATH_ESC'); if buf ~= -1 then vim.api.nvim_buf_call(buf, function() vim.cmd('checktime') end) end" || true
32+
nvim_send "local target = vim.uv.fs_realpath('$FILE_PATH_ESC') or vim.fn.fnamemodify('$FILE_PATH_ESC', ':p') for _, b in ipairs(vim.api.nvim_list_bufs()) do local n = vim.api.nvim_buf_get_name(b) if n ~= '' then local name = vim.uv.fs_realpath(n) or vim.fn.fnamemodify(n, ':p') if name == target then vim.api.nvim_buf_call(b, function() vim.cmd('checktime ' .. b) end) break end end end" || true
3033
fi
3134

3235
# Clear neo-tree change indicators and close the diff tab

0 commit comments

Comments
 (0)