This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/.config/nvim/lua/utils.lua

51 lines
1.1 KiB
Lua
Raw Normal View History

-- Author : swytch
-- Created : Friday Mar 12, 2021 20:07:39 CET
-- License : GPLv3
-- Description : neovim utils file
local M = {} -- The module to export
local cmd = vim.cmd
-- augroup helper
function M.create_augroup(autocmds, name)
cmd("augroup " .. name)
cmd("autocmd!")
for _, autocmd in ipairs(autocmds) do
cmd("autocmd " .. table.concat(autocmd, " "))
end
cmd("augroup END")
end
-- add a path to the rtp
function M.add_rtp(path)
local rtp = vim.o.rtp
rtp = rtp .. "," .. path
end
-- see if a file exists
function M.file_exists(file)
local f = io.open(file, "rb")
if f then f:close() end
return f ~= nil
end
-- get all lines from a file
-- @return table (empty if the file does not exist)
function M.lines_from(file)
if not M.file_exists(file) then return {} end
local lines = {}
for line in io.lines(file) do
lines[#lines] = line
end
return lines
end
function M.copy(args)
return args[1]
end
-- Make it accessible everywhere
_G.utils = M
-- Export the module
return M