35 lines
915 B
Lua
35 lines
915 B
Lua
local function file_exists(file)
|
|
local f = io.open(file, "rb")
|
|
if f then f:close() end
|
|
return f ~= nil
|
|
end
|
|
|
|
local function get_lines_from(file)
|
|
if not file_exists(file) then return {} end
|
|
local lines = {}
|
|
for line in io.lines(file) do
|
|
lines[#lines + 1] = line
|
|
end
|
|
return lines
|
|
end
|
|
|
|
local function header()
|
|
local filetype = vim.api.nvim_buf_get_option(0, 'filetype')
|
|
if filetype ~= "" then
|
|
local current_file_fullpath = debug.getinfo(1, "S").source:sub(2)
|
|
local current_file_path = current_file_fullpath:match("(.*/)")
|
|
local tpl_path = current_file_path .. '../../data/tpl/header-' .. filetype .. '.tpl'
|
|
if file_exists(tpl_path) then
|
|
local lines = get_lines_from(tpl_path)
|
|
vim.api.nvim_put(lines, "l", false, true)
|
|
else
|
|
print("Pas de fichier pour ce filetype (" .. tpl_path .. ")")
|
|
end
|
|
|
|
else
|
|
print("Pas de filetype")
|
|
end
|
|
end
|
|
|
|
return header
|