dotfiles/nvim/lua/clipboard.lua
2026-04-13 00:30:14 +00:00

73 lines
2 KiB
Lua

local os_utils = require("os_utils")
if os_utils.is_linux() then
local wayland_display = os.getenv("WAYLAND_DISPLAY")
local ssh_tty = os.getenv("SSH_TTY")
if os_utils.is_wsl() then
vim.g.clipboard = {
name = "win32yank",
copy = {
["+"] = "win32yank.exe -i --crlf",
["*"] = "win32yank.exe -i --crlf",
},
paste = {
["+"] = "win32yank.exe -o --lf",
["*"] = "win32yank.exe -o --lf",
},
cache_enabled = 0,
}
elseif ssh_tty then
local clip_path = vim.fn.expand("~/.clipboard")
vim.g.clipboard = {
name = "file-clipboard",
copy = {
["+"] = { "tee", clip_path },
["*"] = { "tee", clip_path },
},
paste = {
["+"] = { "cat", clip_path },
["*"] = { "cat", clip_path },
},
cache_enabled = 1,
}
elseif wayland_display then
vim.g.clipboard = {
name = "wl-clipboard",
copy = {
["+"] = "wl-copy",
["*"] = "wl-copy",
},
paste = {
["+"] = "wl-paste",
["*"] = "wl-paste",
},
cache_enabled = 1,
}
else
vim.g.clipboard = {
name = "xclip",
copy = {
["+"] = "xclip -sel clip -i -quiet",
["*"] = "xclip -sel primary -i -quiet",
},
paste = {
["+"] = "xclip -sel clip -o -quiet",
["*"] = "xclip -sel primary -o -quiet",
},
cache_enabled = 1,
}
end
elseif os_utils.is_mac() then
vim.g.clipboard = {
name = "mac-clipboard",
copy = {
["+"] = "pbcopy",
["*"] = "pbcopy",
},
paste = {
["+"] = "pbpaste",
["*"] = "pbpaste",
},
cache_enabled = 1,
}
end