From 92e30040f121f2434682ccb79b2c097fa48a2e9f Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Sun, 13 Oct 2024 22:01:10 +0200 Subject: [PATCH] add c file templates --- .../tui/neovim/runtime/lua/templates/c.lua | 4 +-- .../tui/neovim/runtime/lua/templates/sh.lua | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 modules/tui/neovim/runtime/lua/templates/sh.lua diff --git a/modules/tui/neovim/runtime/lua/templates/c.lua b/modules/tui/neovim/runtime/lua/templates/c.lua index c372590..467917c 100644 --- a/modules/tui/neovim/runtime/lua/templates/c.lua +++ b/modules/tui/neovim/runtime/lua/templates/c.lua @@ -32,8 +32,8 @@ end --- - `filename` (string): The filename of the new file, e.g., "init.lua". return function(opts) local template = { - { pattern = ".*h", content = h_template }, - { pattern = ".*c", content = c_template }, + { pattern = ".*\.h", content = h_template }, + { pattern = ".*\.c", content = c_template }, } return utils.find_entry(template, opts) diff --git a/modules/tui/neovim/runtime/lua/templates/sh.lua b/modules/tui/neovim/runtime/lua/templates/sh.lua new file mode 100644 index 0000000..961610c --- /dev/null +++ b/modules/tui/neovim/runtime/lua/templates/sh.lua @@ -0,0 +1,27 @@ +local utils = require("new-file-template.utils") + +local function bash_template(relative_path, filename) + return [[ +#!/usr/bin/env bash + ]] +end + +local function sh_template(relative_path, filename) + return [[ +#!/usr/bin/env sh + ]] +end + +--- @param opts table +--- A table containing the following fields: +--- - `full_path` (string): The full path of the new file, e.g., "lua/new-file-template/templates/init.lua". +--- - `relative_path` (string): The relative path of the new file, e.g., "lua/new-file-template/templates/init.lua". +--- - `filename` (string): The filename of the new file, e.g., "init.lua". +return function(opts) + local template = { + { pattern = ".*bash", content = bash_template }, + { pattern = ".*sh", content = sh_template }, + } + + return utils.find_entry(template, opts) +end