From 7270ee5021ac54f1b64293d20e6873e107a1c695 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 12 Sep 2026 16:48:59 +0200 Subject: [PATCH] Fix automatic Neovim yanks in remote sessions --- migrations/1788996284.sh | 9 ++++ test/shell.d/neovim-remote-yanks-test.sh | 52 ++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 migrations/1788996284.sh create mode 100755 test/shell.d/neovim-remote-yanks-test.sh diff --git a/migrations/1788996284.sh b/migrations/1788996284.sh new file mode 100644 index 00000000..e47894f8 --- /dev/null +++ b/migrations/1788996284.sh @@ -0,0 +1,9 @@ +echo "Enable automatic Neovim clipboard yanks in remote sessions" + +nvim_provider="$HOME/.config/nvim/lua/config/remote_clipboard.lua" + +if [[ -f $nvim_provider ]] && + grep -qF 'name = "OmarchyRemoteClipboard"' "$nvim_provider" && + ! grep -qF 'vim.opt.clipboard = "unnamedplus"' "$nvim_provider"; then + sed -i '/^ vim.g.clipboard = {/i\ -- LazyVim disables clipboard syncing over SSH; our provider supports it.\n vim.opt.clipboard = "unnamedplus"\n' "$nvim_provider" +fi diff --git a/test/shell.d/neovim-remote-yanks-test.sh b/test/shell.d/neovim-remote-yanks-test.sh new file mode 100755 index 00000000..94b2e7a9 --- /dev/null +++ b/test/shell.d/neovim-remote-yanks-test.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +test_home=$(mktemp -d) +trap 'rm -rf "$test_home"' EXIT +provider="$test_home/.config/nvim/lua/config/remote_clipboard.lua" +migration="$ROOT/migrations/1788996284.sh" + +env HOME="$test_home" bash -euo pipefail "$migration" +[[ ! -e $provider ]] || fail "missing Neovim config is left alone" +pass "missing Neovim config is left alone" + +mkdir -p "$(dirname "$provider")" +printf '%s\n' '-- Custom provider' >"$provider" +cp "$provider" "$test_home/before.lua" +env HOME="$test_home" bash -euo pipefail "$migration" +cmp "$provider" "$test_home/before.lua" || fail "custom provider is preserved" +pass "custom provider is preserved" + +cat >"$provider" <<'LUA' +local M = {} +function M.setup() + if not vim.env.SSH_CONNECTION then + return + end + vim.g.clipboard = { + name = "OmarchyRemoteClipboard", + } +end +return M +LUA +env HOME="$test_home" bash -euo pipefail "$migration" +require_command nvim +cat >"$test_home/check.lua" <<'LUA' +vim.env.SSH_CONNECTION = nil +vim.opt.clipboard = "" +dofile(vim.env.TEST_PROVIDER).setup() +assert(vim.o.clipboard == "") +vim.env.SSH_CONNECTION = "test" +dofile(vim.env.TEST_PROVIDER).setup() +assert(vim.o.clipboard == "unnamedplus") +LUA +env NVIM_LOG_FILE="$test_home/nvim.log" TEST_PROVIDER="$provider" nvim --clean -n --headless -i NONE -l "$test_home/check.lua" +pass "clipboard syncing is enabled inside remote provider setup" + +cp "$provider" "$test_home/once.lua" +env HOME="$test_home" bash -euo pipefail "$migration" +cmp "$provider" "$test_home/once.lua" || fail "migration is idempotent" +pass "migration is idempotent"