aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua
diff options
context:
space:
mode:
authordundargoc <33953936+dundargoc@users.noreply.github.com>2023-04-09 20:46:53 +0200
committerGitHub <noreply@github.com>2023-04-09 20:46:53 +0200
commit41b7586cbb947b3215489fd7445b9bfb6e7008d2 (patch)
treef6559a286ee1f17d864ba13cc428c4f7c444d329 /runtime/lua
parent5d387c338828d176f335f2a9cec8882ecc4ba954 (diff)
downloadrneovim-41b7586cbb947b3215489fd7445b9bfb6e7008d2.tar.gz
rneovim-41b7586cbb947b3215489fd7445b9bfb6e7008d2.tar.bz2
rneovim-41b7586cbb947b3215489fd7445b9bfb6e7008d2.zip
refactor: rewrite clipboard provider healthchecks in Lua
This is required to remove the vimscript checkhealth functions.
Diffstat (limited to 'runtime/lua')
-rw-r--r--runtime/lua/provider/health.lua55
1 files changed, 55 insertions, 0 deletions
diff --git a/runtime/lua/provider/health.lua b/runtime/lua/provider/health.lua
new file mode 100644
index 0000000000..7a17edc848
--- /dev/null
+++ b/runtime/lua/provider/health.lua
@@ -0,0 +1,55 @@
+local M = {}
+
+-- Returns true if `cmd` exits with success, else false.
+local function cmd_ok(cmd)
+ vim.fn.system(cmd)
+ return vim.v.shell_error == 0
+end
+
+local function executable(exe)
+ return vim.fn.executable(exe) == 1
+end
+
+local function is_blank(s)
+ return s:find('^%s*$') ~= nil
+end
+
+local function clipboard()
+ vim.health.report_start('Clipboard (optional)')
+
+ if
+ os.getenv('TMUX')
+ and executable('tmux')
+ and executable('pbpaste')
+ and not cmd_ok('pbpaste')
+ then
+ local tmux_version = string.match(vim.fn.system('tmux -V'), '%d+%.%d+')
+ local advice = {
+ 'Install tmux 2.6+. https://superuser.com/q/231130',
+ 'or use tmux with reattach-to-user-namespace. https://superuser.com/a/413233',
+ }
+ vim.health.report_error('pbcopy does not work with tmux version: ' .. tmux_version, advice)
+ end
+
+ local clipboard_tool = vim.fn['provider#clipboard#Executable']()
+ if vim.g.clipboard and is_blank(clipboard_tool) then
+ local error_message = vim.fn['provider#clipboard#Error']()
+ vim.health.report_error(
+ error_message,
+ "Use the example in :help g:clipboard as a template, or don't set g:clipboard at all."
+ )
+ elseif is_blank(clipboard_tool) then
+ vim.health.report_warn(
+ 'No clipboard tool found. Clipboard registers (`"+` and `"*`) will not work.',
+ ':help clipboard'
+ )
+ else
+ vim.health.report_ok('Clipboard tool found: ' .. clipboard_tool)
+ end
+end
+
+function M.check()
+ clipboard()
+end
+
+return M