initial commit

This commit is contained in:
Scott Graves 2022-07-29 15:52:50 -05:00
parent 13fb9c2dc8
commit 272444e83d
8 changed files with 94 additions and 0 deletions

0
doc/.keep Normal file
View File

View File

View File

@ -0,0 +1,5 @@
local M = {}
M.is_windows = vim.fn.has("win32") == 1 or vim.fn.has("win64") == 1
return M

View File

@ -0,0 +1,34 @@
require("nvim-goodies.string")
local os = require("nvim-goodies.os")
local scan = require("plenary.scandir")
local path = require("plenary.path")
local M = {}
M.directory_sep = M.iff(os.is_windows, "\\\\", "/")
M.not_directory_sep = M.iff(os.is_windows, "/", "\\\\")
function M.create_path(...)
local ret =
path:new({...}):absolute():gsub(M.not_directory_sep, M.directory_sep):gsub(
M.directory_sep .. M.directory_sep,
M.directory_sep
)
return ret
end
function M.get_file_list(dir, extension_no_dot)
extension_no_dot = extension_no_dot or "lua"
local list = {}
local files = scan.scan_dir(dir, {hidden = true, depth = 1})
for _, name in ipairs(files) do
local file_name = string.lower(path:new(name):make_relative(dir))
if file_name:ends_with("." .. extension_no_dot) then
table.insert(list, file_name:sub(1, -5))
end
end
return list
end
return M

View File

@ -0,0 +1,18 @@
local M = {}
function M.check_requires(items)
if type(items) == "string" then
items = {items}
end
for _, s in ipairs(items) do
if not pcall(require, s) then
print("failed requiring:", s, ". maybe try :PlugInstall?")
return false
end
end
return true
end
return M

View File

@ -0,0 +1,21 @@
function string:ends_with(suffix)
return suffix == "" or self:sub(-(#suffix)) == suffix
end
function string:split(sep)
sep = sep or ":"
local fields = {}
local pattern = string.format("([^%s]+)", sep)
_ =
self:gsub(
pattern,
function(c)
fields[#fields + 1] = c
end
)
return fields
end
function string:starts_with(prefix)
return self:sub(1, #prefix) == prefix
end

View File

@ -0,0 +1,12 @@
function table.contains(table, val)
for i = 1, #table do
if table[i] == val then
return true
end
end
return false
end
function table.print_table(o)
return print(vim.inspect(o))
end

4
plugin/nvim-goodies.lua Normal file
View File

@ -0,0 +1,4 @@
if vim.g.loaded_nvim_goodies == 1 then
return
end
vim.g.loaded_nvim_goodies = 1