2022-02-28 11:31:26 +01:00
|
|
|
local M = {}
|
|
|
|
|
2023-09-14 13:13:27 +02:00
|
|
|
--- pretty print lua object
|
|
|
|
--- @param obj any object to pretty print
|
2022-03-04 15:05:34 +01:00
|
|
|
M.dump = function(obj)
|
|
|
|
print(vim.inspect(obj))
|
|
|
|
end
|
|
|
|
|
2022-02-28 11:31:26 +01:00
|
|
|
--- checks if a given command is executable
|
2023-09-14 13:13:27 +02:00
|
|
|
--- @param cmd string? command to check
|
|
|
|
--- @return boolean executable
|
2022-02-28 11:31:26 +01:00
|
|
|
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
|
2023-09-14 13:13:27 +02:00
|
|
|
--- @param cmd string? command to check
|
2024-03-12 13:30:36 +01:00
|
|
|
--- @return fun(): boolean executable
|
2022-02-28 11:31:26 +01:00
|
|
|
M.is_executable_condition = function(cmd)
|
2023-05-06 19:58:30 +02:00
|
|
|
return function()
|
|
|
|
return M.is_executable(cmd)
|
|
|
|
end
|
2022-02-28 11:31:26 +01:00
|
|
|
end
|
|
|
|
|
2023-09-14 13:13:27 +02:00
|
|
|
--- whether or not we are currently in an SSH connection
|
|
|
|
--- @return boolean ssh connection
|
2023-02-11 23:16:35 +01:00
|
|
|
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
|
|
|
|
|
2024-03-12 13:42:21 +01:00
|
|
|
--- list all active LSP clients for specific buffer, or all buffers
|
2023-09-14 13:13:27 +02:00
|
|
|
--- @param bufnr int? buffer number
|
|
|
|
--- @return table all active LSP client names
|
2022-03-02 13:50:32 +01:00
|
|
|
M.list_lsp_clients = function(bufnr)
|
2024-03-12 13:42:21 +01:00
|
|
|
local clients = vim.lsp.get_active_clients({ bufnr = bufnr })
|
2022-03-02 13:50:32 +01:00
|
|
|
local names = {}
|
|
|
|
|
|
|
|
for _, client in ipairs(clients) do
|
|
|
|
table.insert(names, client.name)
|
|
|
|
end
|
|
|
|
|
|
|
|
return names
|
|
|
|
end
|
|
|
|
|
2022-02-28 11:31:26 +01:00
|
|
|
return M
|