Fix automatic Neovim yanks in remote sessions

This commit is contained in:
David Heinemeier Hansson committed 2026-09-12 16:48:59 +02:00
1 parent 31bd80daa4
commit 7270ee5021
2 files changed
+61

No files matched your search

+9
View File
@@ -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
+52
View File
@@ -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"