nix-config/modules/home/vim/lua/ambroisie/utils.lua
Bruno BELANYI d365aba3c0
All checks were successful
ci/woodpecker/push/check Pipeline was successful
home: vim: lua: utils: remove 'dump'
It's now available as 'vim.print'.
2024-03-12 15:13:20 +00:00

52 lines
1.2 KiB
Lua

local M = {}
--- checks if a given command is executable
--- @param cmd string? command to check
--- @return boolean executable
M.is_executable = function(cmd)
return cmd and vim.fn.executable(cmd) == 1
end
--- return a function that checks if a given command is executable
--- @param cmd string? command to check
--- @return fun(): boolean executable
M.is_executable_condition = function(cmd)
return function()
return M.is_executable(cmd)
end
end
--- whether or not we are currently in an SSH connection
--- @return boolean ssh connection
M.is_ssh = function()
local variables = {
"SSH_CONNECTION",
"SSH_CLIENT",
"SSH_TTY",
}
for _, var in ipairs(variables) do
if string.len(os.getenv(var) or "") ~= 0 then
return true
end
end
return false
end
--- list all active LSP clients for specific buffer, or all buffers
--- @param bufnr int? buffer number
--- @return table all active LSP client names
M.list_lsp_clients = function(bufnr)
local clients = vim.lsp.get_active_clients({ bufnr = bufnr })
local names = {}
for _, client in ipairs(clients) do
table.insert(names, client.name)
end
return names
end
return M